제출 #951534

#제출 시각아이디문제언어결과실행 시간메모리
951534Faisal_SaqibBosses (BOI16_bosses)C++17
100 / 100
949 ms1040 KiB
#include <bits/stdc++.h> using namespace std; const int N=5e3+10; vector<int> tp[N]; vector<int> ma[N]; int h[N],val[N]; 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++) { for(int ap=1;ap<=n;ap++) { ma[ap].clear(); h[ap]=1e9; } vp=0; { //Time = O() q.push(i); h[i]=0; while(q.size()) { int f=q.front(); vp++; q.pop(); for(int&ap:tp[f]) { if((h[ap]>(h[f]+1))) { h[ap]=h[f]+1; ma[f].push_back(ap); q.push(ap); } } } } if(vp!=n) continue; ans=min(ans,compute_answer(i)); } cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...