Submission #938909

#TimeUsernameProblemLanguageResultExecution timeMemory
938909vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; const int INF = 1e9; const int MAXN = 5e3; int N; vector<int> children[MAXN + 5]; int vis[MAXN + 5]; queue<int> BFS; int bfs(int start) { while (!BFS.empty()) BFS.pop(); memset(vis, -1, sizeof vis); BFS.push(start); vis[start] = 1; while (!BFS.empty()) { int cur = BFS.front(); BFS.pop(); for (auto next: children[cur]) { if (vis[next] != -1) continue; vis[next] = vis[cur] + 1; BFS.push(next); } } int ans = 0; for (int i = 0; i < N; i++) ans += vis[i]; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; for (int i = 0; i < N; i++) { int sz; cin >> sz; while (sz--) { int u; cin >> u; u--; children[u].push_back(i); } } int ans = INF; for (int i = 0; i < N; i++) ans = min(ans, bfs(i)); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...