Submission #349309

#TimeUsernameProblemLanguageResultExecution timeMemory
349309iANikzadBosses (BOI16_bosses)C++14
100 / 100
781 ms876 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define F first #define S second #define debug(x) cerr<<#x<<" :"<<x<<"\n" #define all(x) x.begin(),x.end() #define pii pair<int,int> #define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie(); #define int long long typedef long long ll; typedef long double ld; const int maxn = 5e3 + 7; const int mod = 1e9 + 7; const int INF = 1e9 + 7; const int mlog = 20; const int SQ = 400; vector<int> adj[maxn]; int mark[maxn], dis[maxn]; int n; int bfs(int root) { queue<int> q; for(int i=1;i<=n;i++) mark[i] = dis[i] = 0; q.push(root); mark[root] = 1; dis[root] = 1; while(!q.empty()) { int v = q.front(); q.pop(); for(int u : adj[v]) { if(mark[u]) continue; mark[u] = true; dis[u] = dis[v] + 1; q.push(u); } } int res = 0; for(int i=1;i<=n;i++) { if(dis[i] == 0) return +INF; res += dis[i]; } return res; } int32_t main() { FAST; cin >> n; for(int i=1;i<=n;i++) { int k; cin >> k; for(int j=1;j<=k;j++) { int boss; cin >> boss; adj[boss].pb(i); } } int ans = +INF; for(int i=1;i<=n;i++) { int res = bfs(i); ans = min(ans, res); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...