# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46265 | ikura355 | Bosses (BOI16_bosses) | C++14 | 640 ms | 1476 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;
#define ll long long
const int maxn = 5000 + 5;
const ll inf = 1e9;
int n;
vector<int> way[maxn];
int d[maxn];
queue<int> q;
ll bfs(int x) {
memset(d,0,sizeof(d));
d[x] = 1; q.push(x);
while(!q.empty()) {
int u = q.front(); q.pop();
for(auto v : way[u]) {
if(!d[v]) {
d[v] = d[u]+1; q.push(v);
}
}
}
ll sum = 0;
for(int x=1;x<=n;x++) {
sum += d[x];
if(d[x]==0) return inf;
}
return sum;
}
int main() {
scanf("%d",&n);
for(int x=1;x<=n;x++) {
int m; scanf("%d",&m);
while(m--) {
int y; scanf("%d",&y);
way[y].push_back(x);
}
}
ll ans = inf;
for(int x=1;x<=n;x++) ans = min(ans, bfs(x));
printf("%lld",ans);
}
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... |