# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39870 | 2018-01-22T17:17:14 Z | igzi | Bosses (BOI16_bosses) | C++14 | 0 ms | 2140 KB |
#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(x); } } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2140 KB | Output is correct |
2 | Incorrect | 0 ms | 2140 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2140 KB | Output is correct |
2 | Incorrect | 0 ms | 2140 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2140 KB | Output is correct |
2 | Incorrect | 0 ms | 2140 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |