# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30680 | zoomswk | Bosses (BOI16_bosses) | C++14 | 1036 ms | 2244 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 <stdio.h>
#include <vector>
#include <queue>
using namespace std;
vector<int> way[5005];
int par[5005], deg[5005];
int val[5005];
int main(){
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++){
int k;
scanf("%d", &k);
while(k--){
int x;
scanf("%d", &x);
way[x].push_back(i);
}
}
int res = 1e9;
for(int root=1; root<=n; root++){
queue<int> q;
q.push(root);
for(int i=1; i<=n; i++) par[i] = 0, deg[i] = 0, val[i] = 1;
par[root] = root;
while(!q.empty()){
int pos = q.front();
q.pop();
for(int v : way[pos]) if(!par[v]){
q.push(v);
par[v] = pos;
deg[pos]++;
}
}
int valid = 1;
for(int i=1; i<=n; i++){
if(!par[i]){ valid = 0; break; }
}
if(!valid) continue;
for(int i=1; i<=n; i++) if(deg[i] == 0) q.push(i);
int cur = 0;
while(!q.empty()){
int pos = q.front();
q.pop();
cur += val[pos];
val[par[pos]] += val[pos];
deg[par[pos]]--;
if(deg[par[pos]] == 0) q.push(par[pos]);
}
if(cur < res) res = cur;
}
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... |