# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134575 | junodeveloper | Bosses (BOI16_bosses) | C++14 | 2 ms | 504 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>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n, D[5010], C[5010];
vector<int> adj[5010];
int main() {
int i,j;
scanf("%d",&n);
for(i=1;i<=n;i++) {
int k;
scanf("%d",&k);
for(j=1;j<=k;j++) {
int x;
scanf("%d",&x);
adj[x].push_back(i);
}
}
queue<int> q;
int u,mx,res=2e9;
for(i=1;i<=n;i++) {
fill(D+1,D+n+1,-1);
fill(C,C+n+1,0);
mx=D[i]=0; q.push(i);
while(!q.empty()) {
u=q.front();q.pop();
C[D[u]]++; mx=max(mx,D[u]);
for(auto& it:adj[u]){
if(D[it]==-1) {
D[it]=D[u]+1;
q.push(it);
}
}
}
int v=0;
for(j=mx;j>=0;j--) {
C[j]+=C[j+1];
v+=C[j];
}
res=min(res,v);
}
printf("%d",res);
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... |