제출 #1057042

#제출 시각아이디문제언어결과실행 시간메모리
1057042adkjtBosses (BOI16_bosses)C++14
100 / 100
439 ms808 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define f first #define s second #define ll long long vector<int> g[5555]; int vis[5555]; queue<pii> qu; int main() { cin.tie()->sync_with_stdio(0); int n;cin>>n; for(int i=1;i<=n;i++) { int m;cin>>m; for(int j=1;j<=m;j++) { int k;cin>>k; g[k].push_back(i); } } ll ans=1e18; for(int i=1;i<=n;i++) { memset(vis,0,sizeof vis); qu.push({i,1});ll cnt=1; int ch=1; vis[i]=1; //cout<<'\n'<<i<<'\n'; while(!qu.empty()) { pii now=qu.front(); qu.pop(); for(auto x:g[now.f]) { if(vis[x]) continue; vis[x]=1; ch++; //cout<<now.f<<' '<<x<<'\n'; qu.push({x,now.s+1}); cnt+=now.s+1; //cout<<cnt<<'\n'; } } if(ch<n) continue; ans=min(cnt,ans); // cout<<ans<<' '<<i<<'\n'; } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...