# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68896 | Abelyan | Bosses (BOI16_bosses) | C++17 | 817 ms | 1560 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.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cassert>
#include <climits>
#include <cstdio>
using namespace std;
typedef long long ll;
struct item {
int v, dpth;
};
const int N = 5006;
vector<int> g[N];
int col[N];
ll ans;
int n;
queue<item> q;
void bfs(int v,int cl) {
int k=1;
q.push({ v,1 });
col[v] = cl;
while (!q.empty()) {
item tv = q.front();
q.pop();
ans += (ll)tv.dpth;
for (auto to : g[tv.v]) {
if (col[to] == cl) continue;
//cout << to << endl;
col[to] = cl;
//cout << to << endl;
k++;
q.push({ to,tv.dpth + 1 });
}
}
if (k != n)ans = LLONG_MAX;
}
int main() {
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int a;
cin >> a;
g[a].push_back(i+1);
}
}
ll mn=LLONG_MAX;
for (int i = 1; i <= n; i++) {
ans = 0;
bfs(i, i);
//cout << i << " " << ans << endl;
mn = min(mn, ans);
}
if (mn == LLONG_MAX)assert(0);
cout << mn << endl;
system("pause");
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... |