제출 #481734

#제출 시각아이디문제언어결과실행 시간메모리
481734RainbowbunnyBosses (BOI16_bosses)C++17
100 / 100
593 ms656 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; int n, ans; int H[MAXN]; vector <int> Adj[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ans = MAXN * MAXN; cin >> n; for(int i = 1; i <= n; i++) { int s; cin >> s; while(s--) { int a; cin >> a; Adj[a].push_back(i); } } for(int i = 1; i <= n; i++) { int tmp = 0, cnt = 0; queue <int> BFS; for(int j = 1; j <= n; j++) { H[j] = -1; } H[i] = 0; BFS.push(i); while(BFS.empty() == false) { int node = BFS.front(); tmp += (H[node] + 1); cnt++; BFS.pop(); for(auto x : Adj[node]) { if(H[x] == -1) { H[x] = H[node] + 1; BFS.push(x); } } } if(cnt == n) { ans = min(ans, tmp); } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...