# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400910 | Pichon5 | Bosses (BOI16_bosses) | C++17 | 1575 ms | 1000 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 <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define vi vector<int>
#define F first
#define ll long long
#define S second
using namespace std;
vector<vi>G,G2;
int suma[5001];
ll sum=0;
void dfs(int nodo, int p){
suma[nodo]=1;
for(int i=0;i<G2[nodo].size();i++){
int to=G2[nodo][i];
if(to==p)continue;
dfs(to,nodo);
suma[nodo]+=suma[to];
}
sum+=suma[nodo];
}
int main()
{
int n,x,k;
cin>>n;
G.resize(n+1);
for(int i=1;i<=n;i++){
cin>>k;
for(int l=0;l<k;l++){
cin>>x;
G[x].pb(i);
//cout<<"conecto "<<x<<" "<<i<<endl;
}
}
//cout<<"check "<<G[2].size()<<endl;
ll res=1e16;
vector<bool>vis;
for(int i=1;i<=n;i++){
//cout<<"candidato a maestro "<<i<<endl;
G2.assign(n+1,vi());
vis.assign(n+1,false);
queue<int>q;
int cant=0;
q.push(i);
vis[i]=1;
while(!q.empty()){
int nodo=q.front();
//cout<<"visito "<<nodo<<endl;
q.pop();
cant++;
for(int l=0;l<G[nodo].size();l++){
int to=G[nodo][l];
//cout<<"hijo "<<to<<endl;
if(!vis[to]){
G2[nodo].pb(to);
G2[to].pb(nodo);
vis[to]=1;
q.push(to);
}
}
}
if(cant!=n){
continue;
}
sum=0;
dfs(i,-1);
//cout<<"pasa "<<sum<<endl;
res=min(res,sum);
}
cout<<res<<endl;
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... |