Submission #39870

# Submission time Handle Problem Language Result Execution time Memory
39870 2018-01-22T17:17:14 Z igzi Bosses (BOI16_bosses) C++14
0 / 100
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

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 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 -