# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397170 | keta_tsimakuridze | Bosses (BOI16_bosses) | C++14 | 1523 ms | 960 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 int long long
#define s second
using namespace std;
const int N=5005,mod=1e9+7,Inf=1e16;
int t,n,fix[N],sum;
queue<int> q;
vector<int>V_[N],V[N];
string s;
int dfs(int u){
int c = 0;
for(int i=0;i<V_[u].size();i++){
c+=dfs(V_[u][i]);
}
sum+=c+1;
return c+1;
}
main(){
// t=1;
cin >> n;
for(int i=1;i<=n;i++){
int c,a;
cin >> c;
while(c--){
cin>>a;
V[a].push_back(i);
}
}
int ans = Inf;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
V_[j].clear();
fix[j] = 0;
}
q.push(i);
fix[i]=1;
int cnt = 0;
while(q.size()) {
int u=q.front();
q.pop();
cnt++;
for(int j=0;j<V[u].size();j++){
if(!fix[V[u][j]]) {
fix[V[u][j]] = 1;
V_[u].push_back(V[u][j]);
q.push(V[u][j]);
}
}
}
sum = 0;
dfs(i);
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... |