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;
typedef long long lo;
#define fi first
#define se second
#define endl "\n"
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define _ << " " <<
const lo inf = 1000000000;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,a[li],k,flag,t,dp[li],vis[li];
int cev;
string s;
vector<int> v[li],vv[li];
inline void dfs(int node,int ata){
dp[node]=1;
for(auto go:vv[node]){
if(go==ata)continue;
dfs(go,node);
dp[node]+=dp[go];
}
//~ cout<<node _ dp[node]<<endl;
}
int32_t main(void){
fio();
cin>>n;
FOR{
cin>>k;
for(int j=1;j<=k;j++){
int x;
cin>>x;
v[x].pb(i);
}
}
cev=1000000000000000000;
FOR{
queue<int> q;
q.push(i);
memset(vis,0,sizeof(vis));
for(int j=1;j<=n;j++)vv[j].clear();
int say=0;
while(q.size()){
say++;
int node=q.front();
q.pop();
vis[node]=1;
for(auto go:v[node]){
if(vis[go])continue;
vv[node].pb(go);
q.push(go);
}
}
if(say!=n){continue;}
int sum=0;
dfs(i,0);
for(int j=1;j<=n;j++)sum+=dp[j];
cev=min(cev,sum);
}
cout<<cev<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |