Submission #107313

#TimeUsernameProblemLanguageResultExecution timeMemory
107313GustavBosses (BOI16_bosses)C++14
100 / 100
797 ms728 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<vi> vvi; const int inf = 0x3f3f3f3f; const ll linf = 123456789012345678; const ll mod = 1000000007; #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl int n; vvi c; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; c = vvi(n); for(int i = 0; i < n; i++){ int k; cin >> k; for(int j = 0; j < k; j++){ int t; cin >> t; c[t-1].push_back(i); } } int ans = inf; for(int i = 0; i < n; i++){ int t_ans = 0; vi seen(n); seen[i] = true; int sc = 1; queue<pi> q; q.push({i,1}); while(!q.empty()){ int e = q.front().first; int d = q.front().second; q.pop(); for(int x : c[e]){ if(seen[x]) continue; seen[x] = 1; q.push({x, d+1}); sc++; } t_ans += d; } if(sc == n) ans = min(t_ans, ans); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...