# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092092 | vjudge1 | Bosses (BOI16_bosses) | C++17 | 486 ms | 856 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>
#define int long long
#define pb push_back
using namespace std;
const int maxn = 5e3 + 10;
int n, h[maxn];
bool mark[maxn];
vector <int> adj[maxn];
queue <int> q;
int32_t main (){
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int x, y, i = 0; i < n; i++){
cin >> x;
for (int y, j = 0; j < x; j++)
cin >> y,
adj[--y].pb(i);
}
int ans = 1e15;
for (int i = 0; i < n; i++){
for (int i = 0; i < n; i++) mark[i] = h[i] = 0;
q.push(i), mark[i] = 1, h[i] = 1;
int tmp = 0, cnt = 0;
while (q.size()){
int v = q.front(); q.pop();
tmp += h[v];
cnt++;
for (auto u : adj[v])
if (!mark[u])
q.push(u), mark[u] = 1, h[u] = h[v] + 1;
}
if (cnt == n) ans = min(ans, tmp);
}
cout << ans;
}
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... |