제출 #695181

#제출 시각아이디문제언어결과실행 시간메모리
695181Ahmed_SolymanBosses (BOI16_bosses)C++14
0 / 100
0 ms340 KiB
#include<bits/stdc++.h> using namespace std; vector<int>adj[5005]; vector<long long>s(5005); vector<bool>vis(5005); void dfs(int n){ vis[n]=1; s[n]=1; for(auto i:adj[n]){ if(!vis[i]){ dfs(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[i].push_back(x); } } long long ans=4e18; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ vis[j]=0; s[j]=0; } dfs(i); long long sum=0; 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...