Submission #971301

#TimeUsernameProblemLanguageResultExecution timeMemory
971301detectivebowonBosses (BOI16_bosses)C++17
0 / 100
1 ms600 KiB
#include<bits/stdc++.h> #define ep emplace #define epb emplace_back #define int long long using namespace std; int n,va[5007],ans=LLONG_MAX; vector<int> adj[5007]; bool visited[5007]; void bfs(int node) { queue<int> q; q.ep(node); while(!q.empty()) { auto u=q.front(); q.pop(); for(auto v:adj[u]) { if(visited[v]) continue; visited[v]=true; va[v]=va[u]+1; q.ep(v); } } } signed main() { cin>>n; for(int i=1;i<=n;i++) { int num; cin>>num; while(num--) { int v; cin>>v; adj[v].epb(i); } } for(int i=1;i<=n;i++) { memset(visited,false,sizeof(visited)); memset(va,0,sizeof(va)); visited[i]=true; va[i]=1; bfs(i); int value=0; for(int j=1;j<=n;j++) { if(!visited[i]) { value=LLONG_MAX; break; } value+=va[j]; } // cout<<value<<"\n"; ans=min(ans,value); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...