Submission #723689

#TimeUsernameProblemLanguageResultExecution timeMemory
723689MardonbekhazratovBosses (BOI16_bosses)C++17
0 / 100
2 ms212 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; const int INF=1e9; vector<vector<int>>v,g; vector<bool>vis; vector<int>a; int n; void dfs(int x){ vis[x]=true; int s=0; for(int z:v[x]){ if(!vis[z]){ g[x].push_back(z); dfs(z); s+=a[z]; } } a[x]+=s; } int solve(int x){ g.resize(n+1); vis.assign(n+1,false); a.assign(n+1,1); dfs(x); int s=0; for(int i=1;i<=n;i++) s+=a[i]; return s; } int main(){ cin>>n; v.resize(n+1); for(int i=1;i<=n;i++){ int k;cin>>k; for(int j=0;j<k;j++){ int x;cin>>x; v[x].push_back(i); } } int res=INF; for(int i=1;i<=n;i++){ res=min(res,solve(i)); } cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...