Submission #374068

#TimeUsernameProblemLanguageResultExecution timeMemory
374068ritul_kr_singhBosses (BOI16_bosses)C++17
100 / 100
784 ms876 KiB
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define sp << " " << #define nl << "\n" vector<vector<int>> g; vector<bool> vis; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; g.resize(n); vis.resize(n); for(int i=0; i<n; ++i){ int k; cin >> k; for(int j=0; j<k; ++j){ int x; cin >> x; g[x-1].push_back(i); } } int ans = 1e18; for(int root=0; root<n; ++root){ for(int i=0; i<n; ++i) vis[i] = false; queue<pair<int, int>> q; vis[root] = true; q.emplace(root, 1); bool ok = true; int curr = 0; while(!q.empty()){ int u = q.front().first, d = q.front().second; q.pop(); curr += d; for(int v : g[u]){ if(!vis[v]){ vis[v] = true; q.emplace(v, d+1); } } } for(int i=0; i<n; ++i) if(!vis[i]) ok = false; if(ok) ans = min(ans, curr); } cout << ans nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...