Submission #796758

#TimeUsernameProblemLanguageResultExecution timeMemory
796758exodus_Bosses (BOI16_bosses)C++14
100 / 100
395 ms628 KiB
#include<bits/stdc++.h> using namespace std; vector<int>adje[5005]; bool vis[5005]; long long biy; int ct; void BFS(int x) { queue<pair<int,int>> q; q.push({x, 1}); vis[x]=true; while(!q.empty()) { int node = q.front().first; int ting = q.front().second; q.pop(); biy+=(ting*1ll); ct++; for (auto itr:adje[node]) { if(vis[itr]) continue; vis[itr]=true; q.push({itr, ting+1}); } } } int main() { int N, t, a; cin >> N; for (int i=1; i<=N; i++) { cin >> t; for (int j=1; j<=t; j++) { cin >> a; adje[a].push_back(i); } } long long jawab = 1e18; for (int i=1; i<=N; i++) { ct = 0; biy = 0; memset(vis, 0, sizeof(vis)); BFS(i); if(ct!=N) continue; jawab = min(jawab, biy); } cout << jawab << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...