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;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
vector<ll>adj[n+1];
for(ll i=1;i<=n;i++){
ll k;
cin>>k;
for(ll j=1;j<=k;j++){
ll x;
cin>>x;
adj[x].pb(i);
}
}
ll ans=1e18;
vector<bool>used(n+1,0);
ll tot[n+1];
vector<ll>g[n+1];
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
g[j].clear();
}
fill(all(used),0);
queue<ll>q;
q.push(i);
used[i]=true;
while(!q.empty()){
ll x=q.front();
q.pop();
for(auto y:adj[x]){
if(!used[y]){
used[y]=true;
g[x].pb(y);
q.push(y);
}
}
}
function <void(ll,ll)> dfs=[&](ll x,ll p){
tot[x]=1;
for(auto y:g[x]){
if(y!=p){
dfs(y,x);
tot[x]+=tot[y];
}
}
};
dfs(i,0);
ll cur=0;
for(ll i=1;i<=n;i++){
cur+=tot[i];
}
ans=min(ans,cur);
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |