# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
724307 | thinknoexit | Bosses (BOI16_bosses) | C++17 | 682 ms | 716 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> adj[5050];
int dis[5050], vis[5050];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1;i <= n;i++) {
int k; cin >> k;
for (int j = 1;j <= k;j++) {
int p;
cin >> p;
adj[p].push_back(i);
}
}
queue<int> q;
int mx, mn = 2e9, cnt;
for (int i = 1;i <= n;i++) {
vis[i] = i;
dis[i] = 1;
q.push(i);
mx = 0, cnt = 0;
int now = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
now += dis[v];
cnt++;
for (auto& x : adj[v]) {
if (vis[x] == i) continue;
dis[x] = dis[v] + 1;
vis[x] = i;
q.push(x);
}
}
if (cnt != n) {
continue;
}
mn = min(mn, now);
}
cout << mn;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |