제출 #880763

#제출 시각아이디문제언어결과실행 시간메모리
880763irmuunBosses (BOI16_bosses)C++17
100 / 100
954 ms1188 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); ll n; cin>>n; vector<ll>adj[n+1]; for(ll i=1;i<=n;i++){ ll k; cin>>k; for(ll j=1;j<=k;j++){ ll x; cin>>x; adj[x].pb(i); } } ll ans=1e18; vector<bool>used(n+1,0); ll tot[n+1]; vector<ll>g[n+1]; for(ll i=1;i<=n;i++){ for(ll j=1;j<=n;j++){ g[j].clear(); } fill(all(used),0); queue<ll>q; q.push(i); used[i]=true; while(!q.empty()){ ll 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(ll,ll)> dfs=[&](ll x,ll 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; bool ok=true; for(ll i=1;i<=n;i++){ cur+=tot[i]; if(!used[i]){ ok=false; } } if(ok) ans=min(ans,cur); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...