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 MAXN=5005;
vector<int> adj[MAXN],edge[MAXN];
int res;
bool visited[MAXN];
int dfs(int now){
int ret=0;
for(auto nxt : edge[now])ret+=dfs(nxt);
res+=(ret+1);
return ret+1;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,k,a;
cin >> n;
for(int i=1;i<=n;i++){
cin >> k;
for(int j=1;j<=k;j++){
cin >> a;
adj[a].push_back(i);
}
}
int ans=1e9;
for(int i=1;i<=n;i++){
memset(visited,0,sizeof(visited));
for(int i=1;i<=n;i++)edge[i].clear();
queue<int> Q;
Q.push(i);
visited[i]=true;
while(!Q.empty()){
int now=Q.front();
Q.pop();
for(auto nxt : adj[now]){
if(!visited[nxt]){
edge[now].push_back(nxt);
visited[nxt]=true;
Q.push(nxt);
}
}
}
bool cek=true;
for(int j=1;j<=n;j++){
if(!visited[j]){
cek=false;
break;
}
}
if(!cek)continue;
res=0;
dfs(i);
ans=min(ans,res);
}
cout << ans << '\n';
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... |