제출 #888757

#제출 시각아이디문제언어결과실행 시간메모리
888757HydrolyzedBosses (BOI16_bosses)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int MxN = 5050; vector<int> adj[MxN]; int dist[MxN]; queue<int> q; inline int bfs(int stp) { memset(dist, -1, sizeof dist); dist[stp] = 1; q.emplace(stp); int sum = 1; while(!q.empty()) { int now = q.front(); q.pop(); for(auto x: adj[now]) { if(dist[x] != -1) { continue; } dist[x] = dist[now] + 1; sum += dist[x]; q.emplace(x); } } return sum; } int main() { cin.tie(nullptr)->ios::sync_with_stdio(false); int n, answer = 1e9 + 100; cin >> n; for(int i=1, m; i<=n; ++i) { cin >> m; for(int _=1, x; _<=m; ++_) { cin >> x; adj[x].emplace_back(i); } } for(int i=1; i<=n; ++i) { int sum = bfs(i); bool ok = true; for(int j=1; j<=n; ++j) { if(dist[i] == -1) { ok = false; break; } } if(ok) { answer = min(answer, sum); } } cout << answer << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...