Submission #951537

#TimeUsernameProblemLanguageResultExecution timeMemory
951537Faisal_SaqibBosses (BOI16_bosses)C++17
100 / 100
912 ms1108 KiB
#include <bits/stdc++.h> using namespace std; const int N=5e3+1; vector<int> tp[N],ma[N]; int val[N]; bitset<5001> vis; int compute_answer(int&v) { val[v]=0; int oth=0; for(int&ap:ma[v]) { oth+=compute_answer(ap); val[v]+=val[ap]; } val[v]++; return val[v]+oth; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int n; cin>>n; for(int i=1;i<=n;i++) { int k; cin>>k; for(int j=1;j<=k;j++) { int p; cin>>p; tp[p].push_back(i); } } int ans=1e9; int vp=0; queue<int> q; for(int i=1;i<=n;i++) { // vis.clear(); vis.reset(); vp=0; { //Time = O() q.push(i); vis[i]=1; ma[i].clear(); while(q.size()) { int f=q.front(); vp++; q.pop(); for(int&ap:tp[f]) { if(!vis[ap]) { vis[ap]=1; ma[ap].clear(); ma[f].push_back(ap); q.push(ap); } } } } if(vp!=n) continue; ans=min(ans,compute_answer(i)); } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...