# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
824276 | AlphaMale06 | Bosses (BOI16_bosses) | C++14 | 841 ms | 900 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 pb push_back
using namespace std;
const int N=5005;
vector<int> adj[N];
vector<int> adj1[N];
bool mark[N];
int ans=0;
int cnt=0;
int dfs(int node, int p){
int ret=1;
for(auto to : adj1[node]){
if(to!=p){
ret+=dfs(to, node);
}
}
ans+=ret;
return ret;
}
void bfs(int node){
mark[node]=true;
cnt=1;
int sum=1;
queue<int> q;
q.push(node);
while(!q.empty()){
int nd=q.front();
for(auto to : adj[nd]){
if(!mark[to]){
q.push(to);
mark[to]=true;
adj1[nd].pb(to);
cnt++;
}
}
q.pop();
}
dfs(node, -1);
}
void clearmark(int n){
for(int i=1; i<= n; i++){
mark[i]=0;
adj1[i].clear();
}
}
int main()
{
int n;
cin >> n;
for(int i=0; i< n; i++){
int k;
cin >> k;
for(int j=0; j< k; j++){
int kita;
cin >> kita;
adj[kita].pb(i+1);
}
}
int mn=1e9;
for(int i=1; i<=n; i++){
bfs(i);
if(cnt==n)mn=min(mn, ans);
clearmark(n+1);
ans=0;
}
cout << mn << '\n';
}
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... |