제출 #733477

#제출 시각아이디문제언어결과실행 시간메모리
733477JellyTheOctopusBosses (BOI16_bosses)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int N; bool adjMat[5001][5001]; int 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; int ans = 0; while (!q.empty()) { array<int, 2> cur = q.front(); int u = cur[0]; int depth = cur[1]; q.pop(); ans += 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) { if (u == v) { continue; } adjMat[u][v] = true; } } int ans = INT_MAX; for (int i = 1; i <= N; i++) { ans = min(ans, bfs(i)+1); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...