Submission #362402

#TimeUsernameProblemLanguageResultExecution timeMemory
362402gratus907Bosses (BOI16_bosses)C++17
100 / 100
691 ms840 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define ll long long #define eps 1e-7 #define all(x) ((x).begin()),((x).end()) #define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; using pii = pair<int, int>; int n; vector <int> G[5050]; int vst[5050]; int32_t main() { usecppio cin >> n; for (int i = 1; i <= n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int p; cin >> p; G[p].push_back(i); } } int ans = INT_MAX; for (int i = 1; i <= n; i++) { memset(vst, 0x7f, sizeof(vst)); int cnt = 0; queue <int> q; q.push(i); cnt++; vst[i] = 1; while (!q.empty()) { int t = q.front(); q.pop(); for (int nxt : G[t]) { if (vst[nxt] > 10000) { vst[nxt] = vst[t] + 1; q.push(nxt); cnt++; } } } if (cnt == n) { int sal = 0; for (int j = 1; j <= n; j++) sal += vst[j]; ans = min(sal, ans); } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...