제출 #971315

#제출 시각아이디문제언어결과실행 시간메모리
971315detectivebowonBosses (BOI16_bosses)C++17
0 / 100
1 ms604 KiB
#include<bits/stdc++.h> #define ep emplace #define epb emplace_back #define int long long using namespace std; int n,va[5007],ans=LLONG_MAX,value; vector<int> adj[5007]; bool visited[5007]; void bfs(int node) { queue<int> q; q.ep(node); va[node]=1; while(!q.empty()) { auto u=q.front(); q.pop(); value+=va[u]; for(auto v:adj[u]) { if(visited[v]) continue; visited[v]=true; va[v]=va[u]+1; q.ep(v); } } } signed main() { cin>>n; for(int i=1;i<=n;i++) { int num; cin>>num; while(num--) { int v; cin>>v; adj[v].epb(i); } } for(int i=1;i<=n;i++) { memset(visited,false,sizeof(visited)); memset(va,0,sizeof(va)); value=0; visited[i]=true; va[i]=1; bfs(i); for(int j=1;j<=n;j++) { if(!visited[i]) { value=LLONG_MAX; break; } } // cout<<value<<"\n"; ans=min(ans,value); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...