제출 #695226

#제출 시각아이디문제언어결과실행 시간메모리
695226Ahmed_SolymanBosses (BOI16_bosses)C++14
0 / 100
1 ms468 KiB
#include<bits/stdc++.h> using namespace std; vector<int>adj[5005]; vector<long long>s(5005); vector<bool>vis(5005); vector<int>g[5005]; void dfs1(int n){ vis[n]=1; for(auto i:adj[n]){ if(!vis[i]){ vis[i]=1; g[n].push_back(i); } } if(g[n].size()){ for(auto i:g[n]){ dfs1(i); } } } void dfs2(int n){ s[n]=1; for(auto i:g[n]){ dfs2(i); s[n]+=s[i]; } } int main(){ int n;cin>>n; for(int i=1;i<=n;i++){ int k;cin>>k; for(int j=0;j<k;j++){ int x;cin>>x; adj[x].push_back(i); } } long long ans=4e18; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ vis[j]=0; s[j]=0; g[j].clear(); } dfs1(i); long long sum=0; bool valid=1; for(int j=1;j<=n;j++){ if(!vis[j]){ valid=0; } } if(valid){ dfs2(i); for(int j=1;j<=n;j++){ sum+=s[j]; } ans=min(ans,sum); } } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...