# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74901 | Vardanyan | Bosses (BOI16_bosses) | C++14 | 635 ms | 1240 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.
//#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
vector<int> g[N];
int n;
long long ans = 10000000000000005;
int mark[N];
int main(){
scanf("%d",&n);
for(int i = 1;i<=n;i++){
int k;
scanf("%d",&k);
for(int j = 1;j<=k;j++){
int x;
scanf("%d",&x);
g[x].push_back(i);
}
}
for(int i = 1;i<=n;i++){
long long val = 0;
memset(mark,0,sizeof(mark));
mark[i] = 1;
queue<int> q;
q.push(i);
int cnt = 0;
while(!q.empty()){
int v = q.front();
q.pop();
cnt++;
val+=mark[v];
if(val>=ans) break;
for(int j = 0;j<g[v].size();j++){
int to = g[v][j];
if(mark[to]) continue;
mark[to] = mark[v]+1;
q.push(to);
}
}
if(cnt == n)
ans = min(ans,val);
}
printf("%lld\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... |