Submission #256997

#TimeUsernameProblemLanguageResultExecution timeMemory
256997rama_pangBosses (BOI16_bosses)C++14
100 / 100
875 ms760 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int N; cin >> N; vector<vector<int>> adj(N); for (int i = 0; i < N; i++) { int k; cin >> k; while (k--) { int a; cin >> a; a--; adj[a].emplace_back(i); } } auto Solve = [&](int s) -> long long { vector<int> dist(N, -1); queue<int> q; q.emplace(s); dist[s] = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (auto v : adj[u]) { if (dist[v] == -1) { dist[v] = dist[u] + 1; q.emplace(v); } } } if (count(begin(dist), end(dist), -1) > 0) { return 1e18; } long long ans = 0; for (int i = 0; i < N; i++) { ans += dist[i] + 1; } return ans; }; long long ans = 1e18; for (int i = 0; i < N; i++) { ans = min(ans, Solve(i)); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...