Submission #1296158

#TimeUsernameProblemLanguageResultExecution timeMemory
1296158hiepsimauhongBosses (BOI16_bosses)C++20
100 / 100
386 ms768 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(I, L, R) for(int I(L) ; I <= (int)R ; ++I) #define FOD(I, R, L) for(int I(R) ; I >= (int)L ; --I) #define FOA(I, A) for(auto &I : A) #define print(A,L,R) FOR(OK, L, R){if(A[OK]<=-oo / 10||A[OK]>=oo)cout<<"- ";else cout<<A[OK]<<' ';}cout<<'\n'; #define prints(A) FOA(OK, A){cout<<OK<<' ';}cout << '\n'; #define printz(A,L,R) FOR(OK, 0, L){FOR(KO, 0, R){if(A[OK][KO]>-oo&&A[OK][KO]<oo)cout<<A[OK][KO]<<' ';else cout << "- ";} cout << '\n';}cout << '\n'; #define fs first #define sd second #define ii pair<int,int> #define iii pair<int, ii> #define all(A) A.begin(), A.end() #define quickly ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define FILE "FILE" const int N = 5000 + 5; const int mod = 1e9 + 9999; const int oo = 1e18; struct Modint{ int x; Modint(){x = 0;} Modint(int _x){x = (_x + mod) % mod;} Modint operator + (const Modint &other) const{ return Modint((x + other.x) % mod); } Modint operator - (const Modint &other) const{ return Modint((x - other.x + mod) % mod); } Modint operator * (const Modint &other) const{ return Modint((1LL * x * other.x) % mod); } void operator += (const Modint &other) { *this = *this + other; } void operator -= (const Modint &other) { *this = *this - other; } void operator *= (const Modint &other) { *this = *this * other; } friend ostream& operator << (ostream& os, const Modint &other){ return os << other.x; } }; int n; int dist[N]; queue<int> q; vector<int> g[N]; int BFS(int start){ FOR(i, 1, n){ dist[i] = 0; } dist[start] = 1; q.push(start); while(!q.empty()){ int u = q.front(); q.pop(); FOA(v, g[u]){ if(!dist[v]){ dist[v] = dist[u] + 1; q.push(v); } } } int res = 0; FOR(i, 1, n){ if(dist[i] == 0) return oo; res += dist[i]; } return res; } signed main(){ quickly if(fopen(FILE".inp", "r")){ freopen(FILE".inp", "r", stdin); freopen(FILE".out", "w", stdout); } cin >> n; FOR(i, 1, n){ int len; cin >> len; FOR(j, 1, len){ int x; cin >> x; g[x].push_back(i); } } int ans = oo; FOR(i, 1, n){ ans = min(ans, BFS(i)); } cout << ans; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:81:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |                 freopen(FILE".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:82:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |                 freopen(FILE".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...