Submission #99566

# Submission time Handle Problem Language Result Execution time Memory
99566 2019-03-05T08:43:01 Z tushar_2658 Bosses (BOI16_bosses) C++14
100 / 100
569 ms 732 KB
#include "bits/stdc++.h"
using namespace std;

int dis[5005];
int n;
vector<int> edges[5005];

int bfs(int s){
    memset(dis, -1, sizeof dis);
    dis[s] = 1;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        s = que.front();
        que.pop();
        for(auto i : edges[s]){
            if(dis[i] != -1)continue;
            dis[i] = dis[s] + 1;
            que.push(i);
        }
    }
    int ret = 0;
    for(int i=1; i<=n; i++){
        if(dis[i] == -1)return -1;
        ret += dis[i];
    }return ret;
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        int timer;
        scanf("%d", &timer);
        while(timer--){
            int x;
            scanf("%d", &x);
            edges[x].emplace_back(i);
        }
    }
    int ans = INT_MAX;
    for(int i=1; i<=n; i++){
        int x = bfs(i);
        if(x == -1)continue;
        ans = min(ans, x);
    }cout<<ans<<endl;
}

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bosses.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &timer);
         ~~~~~^~~~~~~~~~~~~~
bosses.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 105 ms 512 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 509 ms 640 KB Output is correct
17 Correct 544 ms 732 KB Output is correct
18 Correct 569 ms 640 KB Output is correct