# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99566 | tushar_2658 | Bosses (BOI16_bosses) | C++14 | 569 ms | 732 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |