제출 #79518

#제출 시각아이디문제언어결과실행 시간메모리
79518minhtung0404Bosses (BOI16_bosses)C++17
100 / 100
793 ms1084 KiB
//https://oj.uz/problem/view/BOI16_bosses #include<bits/stdc++.h> const int N = 5005; using namespace std; vector <int> adj[N]; int n, d[N], ans = N*N; void bfs(int u){ int sum = 0, cnt = 0; for (int i = 1; i <= n; i++) d[i] = 0; queue <int> mq; mq.push(u); d[u] = 1; while(mq.size()){ int u = mq.front(); mq.pop(); sum += d[u]; cnt++; for (auto v : adj[u]){ if (!d[v]){ d[v] = d[u] + 1; mq.push(v); } } } if (cnt == n) ans = min(ans, sum); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { int k, x; cin >> k; while (k--){ cin >> x; adj[x].push_back(i); } } for (int i = 1; i <= n; i++) bfs(i); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...