Submission #733481

#TimeUsernameProblemLanguageResultExecution timeMemory
733481JellyTheOctopusBosses (BOI16_bosses)C++17
0 / 100
1 ms304 KiB
#include <bits/stdc++.h> using namespace std; int N; bool adjMat[5001][5001]; long long bfs(int root) { vector<bool> seen(N+1); queue<array<int, 2>> q; // node, depth q.push({root, 1}); // starting depth at one seen[root] = true; long long ans = 0; while (!q.empty()) { array<int, 2> cur = q.front(); int u = cur[0]; int depth = cur[1]; q.pop(); ans += (long long)depth; for (int v = 1; v <= N; v++) { if (adjMat[u][v] && !seen[v]) { q.push({v, depth+1}); seen[v] = true; } } } return ans; } int main() { cin >> N; cin.ignore(); for (int v = 1; v <= N; v++) { string line; getline(cin, line); istringstream iss(line); int u; while (iss >> u) { adjMat[u][v] = true; } } long long ans = LLONG_MAX; for (int i = 1; i <= N; i++) { if (adjMat[i][i]) continue; ans = min(ans, bfs(i)); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...