제출 #936215

#제출 시각아이디문제언어결과실행 시간메모리
936215adkjtBosses (BOI16_bosses)C++14
0 / 100
1 ms604 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define f first #define s second 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); } } int ans=INT_MAX; for(int i=1;i<=n;i++) { memset(vis,0,sizeof vis); qu.push({i,1});int cnt=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; //cout<<now.f<<' '<<x<<'\n'; qu.push({x,now.s+1}); cnt+=now.s+1; //cout<<cnt<<'\n'; } } 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...