Submission #857341

#TimeUsernameProblemLanguageResultExecution timeMemory
857341teeslaBosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; vector<int> vis; int res = 0; void bfs(int x){ queue<pair<int,int>> q; q.push({x,1}); vis[x] = 1; while(!q.empty()){ auto [a,b] = q.front();q.pop(); if(vis[a]< b) continue; res += b; for(auto i: adj[a]){ if(vis[i] != -1) continue; vis[i] = b + 1; q.push({i, vis[i]}); } } } int main(){ int n; cin >> n; adj.resize(n); for(int i=0; i<n; i++){ int k; cin >> k; for(int j =0; j<k; j++){ int a; cin >> a; a--; adj[a].push_back(i); } } int menor = 0; for(int i=0; i<n; i++){ vis.assign(n,-1); res = 0; bfs(i); if(i ==0) menor =res; else menor = min(menor, res); } cout << menor << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...