# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
771317 | pera | Bosses (BOI16_bosses) | C++17 | 5 ms | 8168 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;
#define int long long
const int N = 2e5 + 1;
int n , ans , c;
vector<int> g[N] , v(N) , d(N);
void dfs(int u){
v[u] = 1;
c += d[u];
for(int i = 0;i < g[u].size();i ++){
if(!v[g[u][i]]){
d[g[u][i]] = d[u] + 1;
dfs(g[u][i]);
}
}
}
main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i ++){
int k;cin >> k;
for(int j = 1;j <= k;j ++){
int v;cin >> v;
g[v].push_back(i);
}
}
ans = INT_MAX;
for(int boss = 1;boss <= n;boss ++){
for(int i = 1;i <= n;i ++){
d[i] = v[i] = 0;
}
c = 0;
d[boss] = 1;
dfs(boss);
if(accumulate(v.begin() , v.end() , 0) == n) ans = min(ans , c);
}
cout << ans << endl;
}
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... |