# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532224 | andecaandeci | Bosses (BOI16_bosses) | C++17 | 770 ms | 604 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 pb push_back
#define fi first
#define se second
const int maxn = 5e3+1;
int minum = 1e9;
int main(){
int n;
scanf("%d",&n);
vector<int> adj[maxn];
for(int i=1;i<=n;i++){
int k;
scanf("%d",&k);
for(int j=0;j<k;j++){
int x;
scanf("%d",&x);
adj[x].pb(i);
}
}
queue<int> q;
int temp = 0;
for(int i=1;i<=n;i++){
if(adj[i].empty()) continue;
vector<bool> vis(n+1);
q.push(i);
vis[i] = 1;
int node = 0,cnt = 1,ans = n;
while(!q.empty()){
temp = q.front();
q.pop();
node++;
for(auto it : adj[temp]){
if(!vis[it]){
vis[it] = 1;
q.push(it);
}
}
cnt--;
if(cnt == 0){
ans += (n - node);
cnt = (int) q.size();
}
}
if(node == n){
minum = min(minum,ans);
}
}
printf("%d",minum);
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... |