제출 #83028

#제출 시각아이디문제언어결과실행 시간메모리
83028FedericoSPark (BOI16_park)C++14
0 / 100
5 ms832 KiB
#include <iostream> #include <queue> #include <assert.h> using namespace std; typedef long long int ll; ll N,K; ll x; bool B[5005][5005],V[5005]; int P[5005]; queue<int> L; vector<int> grafo[5005]; ll ans=1e18,res; ll S[5005]; int c=-1; void DFS(int k){ for(int f:grafo[k]){ DFS(f); S[k]+=S[f]; } S[k]++; res+=S[k]; } int main(){ cin>>N; for(int i=0;i<N;i++){ cin>>K; if(!K) c=i; for(int j=0;j<K;j++){ cin>>x; x--; B[i][x]=true; } } for(int i=0;i<N;i++){ if(c!=-1 and c!=i) continue; fill(V,V+N,false); L.push(i); V[i]=true; for(int j=0;j<N;j++) grafo[j].clear(); fill(S,S+N,0); res=0; x=1; while(!L.empty()){ for(int j=0;j<N;j++) if(!V[j] and B[j][L.front()]){ x++; grafo[L.front()].push_back(j); L.push(j); V[j]=true; } L.pop(); } if(x!=N) continue; DFS(i); ans=min(ans,res); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...