Submission #724307

#TimeUsernameProblemLanguageResultExecution timeMemory
724307thinknoexitBosses (BOI16_bosses)C++17
100 / 100
682 ms716 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> adj[5050]; int dis[5050], vis[5050]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; for (int i = 1;i <= n;i++) { int k; cin >> k; for (int j = 1;j <= k;j++) { int p; cin >> p; adj[p].push_back(i); } } queue<int> q; int mx, mn = 2e9, cnt; for (int i = 1;i <= n;i++) { vis[i] = i; dis[i] = 1; q.push(i); mx = 0, cnt = 0; int now = 0; while (!q.empty()) { int v = q.front(); q.pop(); now += dis[v]; cnt++; for (auto& x : adj[v]) { if (vis[x] == i) continue; dis[x] = dis[v] + 1; vis[x] = i; q.push(x); } } if (cnt != n) { continue; } mn = min(mn, now); } cout << mn; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:19:9: warning: variable 'mx' set but not used [-Wunused-but-set-variable]
   19 |     int mx, mn = 2e9, cnt;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...