제출 #1108454

#제출 시각아이디문제언어결과실행 시간메모리
11084540pt1mus23Bosses (BOI16_bosses)C++14
100 / 100
431 ms856 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int #define ins insert #define pb push_back #define endl '\n' #define putr(x) cout<<x<<endl;return; #define all(x) x.begin(),x.end() const int mod = 1e9 +7, sze = 5e3 +10, inf = LLONG_MAX, LG = 20; vector<int> graph[sze]; int used[sze]; void rush(){ int n; cin>>n; for(int i=1;i<=n;i++){ int k;cin>>k; for(int j=1;j<=k;j++){ int u;cin>>u; graph[u].pb(i); } } int ans=inf; for(int i=1;i<=n;i++){ queue<pair<int,int>> q; q.push({i,1}); int qaldi= n; for(int j=0;j<=n;j++){ used[j]=0; } used[i]=1; int curr= 0; while(!q.empty()){ auto node = q.front();q.pop(); qaldi--; curr += node.second; for(auto v:graph[node.first]){ if(!used[v]){ used[v]=1; q.push({v,node.second +1}); } } } if(!qaldi){ ans=min(ans,curr); } } putr(ans); } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin>>tt; while(tt--){ rush(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...