# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27021 | bill_kondo | Bosses (BOI16_bosses) | C++14 | 703 ms | 2316 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 pb push_back
#define debug(args...) fprintf(stderr,args)
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define REP(i,a,b) for(int i = a; i >= b; --i)
typedef long long ll;
typedef pair<int,int>pii;
const int maxn = 5e3 + 10;
const ll INF = 1e18;
int n;
vector<int>g[maxn];
bool mrk[maxn];
ll dis[maxn];
ll solve(int root){
FOR(i,1,n){
mrk[i] = false;
dis[i] = INF;
}
queue<int>Q;
dis[root] = 1;
mrk[root] = true;
Q.push(root);
while(!Q.empty()){
int v = Q.front();
Q.pop();
for(auto u: g[v])
if(!mrk[u]){
mrk[u] = true;
dis[u] = dis[v] + 1;
Q.push(u);
}
}
ll ret = 0;
FOR(i,1,n){
if(!mrk[i]) return INF;
ret += dis[i];
}
return ret;
}
int main(){
scanf("%d",&n);
FOR(i,1,n){
int k;
scanf("%d",&k);
while(k--){
int node;
scanf("%d",&node);
g[node].pb(i);
}
}
ll ans = INF;
FOR(i,1,n) ans = min(ans,solve(i));
printf("%lld\n",ans);
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... |