Submission #32264

#TimeUsernameProblemLanguageResultExecution timeMemory
32264dqhungdlBosses (BOI16_bosses)C++14
100 / 100
653 ms2464 KiB
#include <bits/stdc++.h> using namespace std; int n,res=1e9,h[5005],Q[5005]; vector<int> g[5005]; void BFS(int u) { for(int i=1;i<=n;i++) h[i]=0; h[u]=1; Q[1]=u; int l=1,r=1; while(l<=r) { int u=Q[l++]; for(int i=0;i<g[u].size();i++) if(h[g[u][i]]==0) { Q[++r]=g[u][i]; h[g[u][i]]=h[u]+1; } } if(r==n) { int sum=0; for(int i=1;i<=n;i++) sum+=h[i]; res=min(res,sum); } } int main() { ios_base::sync_with_stdio(false); //freopen("BOSSES.INP","r",stdin); cin>>n; int k,x; for(int i=1;i<=n;i++) { cin>>k; while(k--) { cin>>x; g[x].push_back(i); } } for(int i=1;i<=n;i++) BFS(i); cout<<res; }

Compilation message (stderr)

bosses.cpp: In function 'void BFS(int)':
bosses.cpp:17:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<g[u].size();i++)
                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...