# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397179 | keta_tsimakuridze | Bosses (BOI16_bosses) | C++14 | 840 ms | 672 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 f first
#define s second
using namespace std;
const int N=5005,mod=1e9+7,Inf=1e16;
int t,n,fix[N],h[N];
long long sum;
queue<int> q;
vector<int>V[N];
string s;
main(){
// t=1;
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin >> n;
for(int i=1;i<=n;i++){
int c,a;
cin >> c;
while(c--){
cin>>a;
V[a].push_back(i);
}
}
long long ans = Inf;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
fix[j] = 0;
}
q.push(i);
fix[i]=1; h[i] = 1;
int cnt = 0;
sum = 0;
while(q.size()) {
int u=q.front();
q.pop();
cnt++;
sum+=h[u];
for(int j=0;j<V[u].size();j++){
if(!fix[V[u][j]]) {
fix[V[u][j]] = 1;
h[V[u][j]] = h[u] + 1;
q.push(V[u][j]);
}
}
}
if(cnt==n)ans=min(ans,sum);
}
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... |