# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400913 | Pichon5 | Bosses (BOI16_bosses) | C++17 | 1577 ms | 1004 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 pb push_back
#define vi vector<int>
#define F first
#define ll long long
#define S second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<vi>G,G2;
ll suma[5001];
ll sum=0;
vector<bool>vis;
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()
{
fast
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);
}
}
ll res=1e16;
for(int i=1;i<=n;i++){
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();
q.pop();
cant++;
for(int l=0;l<G[nodo].size();l++){
int to=G[nodo][l];
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);
res=min(res,sum);
}
cout<<res<<"\n";
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... |