# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24438 | Bruteforceman | Bosses (BOI16_bosses) | C++11 | 656 ms | 2292 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;
vector <int> g[5005];
int d[5005];
int n;
int query(int root) {
memset(d, -1, sizeof d);
queue <int> Q;
Q.push(root);
d[root] = 1;
while(!Q.empty()) {
int x = Q.front();
Q.pop();
for(auto i : g[x]) {
if(d[i] == -1) {
d[i] = 1 + d[x];
Q.push(i);
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
if(d[i] == -1) return -1;
else ans += d[i];
}
return ans;
}
int main(int argc, char const *argv[])
{
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
int p;
scanf("%d", &p);
for(int j = 1; j <= p; j++) {
int x;
scanf("%d", &x);
g[x].push_back(i);
}
}
int ans = INT_MAX;
for(int i = 1; i <= n; i++) {
int x = query(i);
if(x == -1) continue;
ans = min(ans, x);
}
printf("%d\n", ans);
return 0;
}
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... |