Submission #69795

#TimeUsernameProblemLanguageResultExecution timeMemory
69795Bodo171Bosses (BOI16_bosses)C++14
100 / 100
629 ms1004 KiB
#include <iostream> #include <fstream> #include <climits> #include <vector> using namespace std; const int nmax=5005; vector<int> ad[nmax]; int q[nmax],d[nmax],nr[nmax]; int n,m,i,j,a,b,p,u,start,x,nod,k; int ans; int bfs() { q[u=1]=start; d[start]=1; for(p=1;p<=u;p++) { x=q[p]; for(i=0;i<ad[x].size();i++) { nod=ad[x][i]; if(!d[nod]) d[nod]=d[x]+1,q[++u]=nod; } } int ret=0; bool busit=0; for(i=1;i<=n;i++) { ret+=1LL*d[i]; if(!d[i]) busit=1; d[i]=0; } if(busit) return INT_MAX; return ret; } int main() { // freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n; for(i=1;i<=n;i++) { cin>>k; for(j=1;j<=k;j++) { cin>>x; ad[x].push_back(i); } } ans=INT_MAX; for(start=1;start<=n;start++) ans=min(ans,bfs()); cout<<ans; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int bfs()':
bosses.cpp:18:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<ad[x].size();i++)
                 ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...