Submission #880759

#TimeUsernameProblemLanguageResultExecution timeMemory
880759irmuunBosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int>adj[n+1]; for(int i=1;i<=n;i++){ int k; cin>>k; for(int j=1;j<=k;j++){ int x; cin>>x; adj[x].pb(i); } } ll ans=1e9; vector<bool>used(n+1,0); int tot[n+1]; vector<int>g[n+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ g[j].clear(); } fill(all(used),0); queue<int>q; q.push(i); used[i]=true; while(!q.empty()){ int x=q.front(); q.pop(); for(auto y:adj[x]){ if(!used[y]){ used[y]=true; g[x].pb(y); q.push(y); } } } function <void(int,int)> dfs=[&](int x,int p){ tot[x]=1; for(auto y:g[x]){ if(y!=p){ dfs(y,x); tot[x]+=tot[y]; } } }; dfs(i,0); ll cur=0; for(int i=1;i<=n;i++){ cur+=tot[i]; } ans=min(ans,cur); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...