Submission #83030

#TimeUsernameProblemLanguageResultExecution timeMemory
83030FedericoSBosses (BOI16_bosses)C++14
67 / 100
1559 ms1448 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> Q; vector<int> albero[5005]; vector<int> grafo[5005]; ll ans=1e18,res; ll S[5005]; int c=-1; void DFS(int k){ for(int f:albero[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; for(int j=0;j<K;j++){ cin>>x; x--; grafo[x].push_back(i); } } for(int i=0;i<N;i++){ fill(V,V+N,false); V[i]=true; Q.push(i); for(int j=0;j<N;j++) albero[j].clear(); fill(S,S+N,0); res=0; x=1; while(!Q.empty()){ int nodo=Q.front(); Q.pop(); for(int f:grafo[nodo]) if(!V[f]){ Q.push(f); V[f]=true; albero[nodo].push_back(f); x++; } } 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...