제출 #1096937

#제출 시각아이디문제언어결과실행 시간메모리
1096937Zone_zoneeBosses (BOI16_bosses)C++17
100 / 100
388 ms780 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int> adj[5050]; bool vis[5050]; int bfs(int f){ memset(vis, 0, sizeof vis); int res = 0, cnt = 0; queue<pair<int, int>> q; q.emplace(f, 1); vis[f] = 1; while(!q.empty()){ auto [u, d] = q.front(); q.pop(); res += d; cnt++; for(int v : adj[u]){ if(vis[v]) continue; vis[v] = 1; q.emplace(v, d + 1); } } if(cnt == n) return res; return 1e9; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; ++i){ int m; cin >> m; while(m--){ int v; cin >> v; adj[v].emplace_back(i); } } int ans = 1e9; for(int i = 1; i <= n; ++i){ ans = min(ans, bfs(i)); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...