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;
const int N=5e3+1;
vector<int> tp[N],ma[N];
int val[N];
bitset<5001> vis;
int compute_answer(int&v)
{
val[v]=0;
int oth=0;
for(int&ap:ma[v])
{
oth+=compute_answer(ap);
val[v]+=val[ap];
}
val[v]++;
return val[v]+oth;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int k;
cin>>k;
for(int j=1;j<=k;j++)
{
int p;
cin>>p;
tp[p].push_back(i);
}
}
int ans=1e9;
int vp=0;
queue<int> q;
for(int i=1;i<=n;i++)
{
// vis.clear();
vis.reset();
vp=0;
{
//Time = O()
q.push(i);
vis[i]=1;
ma[i].clear();
while(q.size())
{
int f=q.front();
vp++;
q.pop();
for(int&ap:tp[f])
{
if(!vis[ap])
{
vis[ap]=1;
ma[ap].clear();
ma[f].push_back(ap);
q.push(ap);
}
}
}
}
if(vp!=n)
continue;
ans=min(ans,compute_answer(i));
}
cout<<ans;
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... |