# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81547 | arman_ferdous | Bosses (BOI16_bosses) | C++17 | 625 ms | 1292 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;
const int N = 5010;
int n;
vector<int> g[N];
int d[N];
int bfs(int u) {
queue<int> q; q.push(u);
memset(d,-1,sizeof d); d[u] = 1;
while(!q.empty()) {
int u = q.front(); q.pop();
for(int v : g[u]) if(d[v] == -1) {
d[v] = d[u] + 1;
q.push(v);
}
} int ret = 0;
for(int i = 1; i <= n; i++) {
if(d[i] == -1) return (int)2e9;
ret += d[i];
} return ret;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
int sz, j; scanf("%d", &sz);
while(sz--) {
scanf("%d", &j);
g[j].push_back(i);
}
}
int ans = (int)2e9;
for(int i = 1; i <= n; i++)
ans = min(ans, bfs(i));
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... |