Submission #39871

#TimeUsernameProblemLanguageResultExecution timeMemory
39871igziBosses (BOI16_bosses)C++14
100 / 100
680 ms2272 KiB
#include <bits/stdc++.h> #define maxN 5005 using namespace std; vector <int> adj[maxN]; bool visited[maxN]; int n,i,x,y,ans=INT_MAX; int bfs(int node){ queue <int> q; int ans=0,d[maxN]; visited[node]=true; q.push(node); d[node]=1; while(!q.empty()){ int c=q.front(); q.pop(); for(int i=0;i<adj[c].size();i++){ if(!visited[adj[c][i]]){ visited[adj[c][i]]=true; q.push(adj[c][i]); d[adj[c][i]]=d[c]+1; } } } for(int i=1;i<=n;i++){ if(!visited[i]) return -1; ans+=d[i]; } return ans; } int main() { cin>>n; for(i=1;i<=n;i++){ scanf("%d", &x); for(int j=0;j<x;j++){ scanf("%d", &y); adj[y].push_back(i); } } for(i=1;i<=n;i++){ for(int j=0;j<=n;j++){ visited[j]=false; } int c=bfs(i); if(c==-1) continue; if(c<ans) ans=c; } cout<<ans<<endl; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int bfs(int)':
bosses.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<adj[c].size();i++){
                  ^
bosses.cpp: In function 'int main()':
bosses.cpp:36:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
                        ^
bosses.cpp:38:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &y);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...