# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39871 | 2018-01-22T17:21:56 Z | igzi | Bosses (BOI16_bosses) | C++14 | 680 ms | 2272 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(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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2140 KB | Output is correct |
2 | Correct | 0 ms | 2140 KB | Output is correct |
3 | Correct | 0 ms | 2140 KB | Output is correct |
4 | Correct | 0 ms | 2140 KB | Output is correct |
5 | Correct | 0 ms | 2140 KB | Output is correct |
6 | Correct | 1 ms | 2140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2140 KB | Output is correct |
2 | Correct | 0 ms | 2140 KB | Output is correct |
3 | Correct | 0 ms | 2140 KB | Output is correct |
4 | Correct | 0 ms | 2140 KB | Output is correct |
5 | Correct | 0 ms | 2140 KB | Output is correct |
6 | Correct | 1 ms | 2140 KB | Output is correct |
7 | Correct | 0 ms | 2140 KB | Output is correct |
8 | Correct | 0 ms | 2140 KB | Output is correct |
9 | Correct | 0 ms | 2140 KB | Output is correct |
10 | Correct | 0 ms | 2140 KB | Output is correct |
11 | Correct | 0 ms | 2140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2140 KB | Output is correct |
2 | Correct | 0 ms | 2140 KB | Output is correct |
3 | Correct | 0 ms | 2140 KB | Output is correct |
4 | Correct | 0 ms | 2140 KB | Output is correct |
5 | Correct | 0 ms | 2140 KB | Output is correct |
6 | Correct | 1 ms | 2140 KB | Output is correct |
7 | Correct | 0 ms | 2140 KB | Output is correct |
8 | Correct | 0 ms | 2140 KB | Output is correct |
9 | Correct | 0 ms | 2140 KB | Output is correct |
10 | Correct | 0 ms | 2140 KB | Output is correct |
11 | Correct | 0 ms | 2140 KB | Output is correct |
12 | Correct | 6 ms | 2272 KB | Output is correct |
13 | Correct | 4 ms | 2272 KB | Output is correct |
14 | Correct | 157 ms | 2272 KB | Output is correct |
15 | Correct | 13 ms | 2272 KB | Output is correct |
16 | Correct | 644 ms | 2272 KB | Output is correct |
17 | Correct | 679 ms | 2272 KB | Output is correct |
18 | Correct | 680 ms | 2272 KB | Output is correct |