Submission #1018742

#TimeUsernameProblemLanguageResultExecution timeMemory
1018742coolboy19521Bosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include "bits/stdc++.h" #define int long long using namespace std; const int inf = 1e18 + 18; const int sz = 5e3 + 15; vector<int> aj[sz]; bool vi[sz]; int bfs(int x) { fill_n(vi, sz, false); queue<pair<int,int>> q; q.push(make_pair(1,x)); int r = 0; while (!q.empty()) { auto tp = q.front(); q.pop(); int d = tp.first; int v = tp.second; if (vi[v]) continue; vi[v] = true; r += d; // cout << v << ' ' << d << '\n'; for (int u : aj[v]) if (!vi[u]) q.push(make_pair(d + 1, u)); } return r; } signed 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 v; cin >> v; aj[v].push_back(i); } } int mn = inf; for (int i = 1; i <= n; i ++) { int r = bfs(i); mn = min(mn, r); // cout << i << ' ' << r << '\n'; } cout << mn << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...