This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
* author : Apiram
* created: 27.06.2023 03:25:28
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<vector<int>>adj(n);
for (int i = 0;i<n;++i){
int k;cin>>k;
for (int j = 0;j<k;++j){
int x;cin>>x;
--x;
adj[x].push_back(i);
}
}
int cur = n + 1;
vector<int>visited(n,false);
function<int(int,int)>dfs = [&](int u,int v){
if (v == n)return 0;
visited[u] = true;
int ans = n + 1;
for (auto x:adj[u]){
if (!visited[x]){
ans = min(ans,dfs(x,v + 1) + 1);
}
}
visited[u] = false;
return ans;
};
for (int i = 0;i<n;++i){
for (int j = 0;j<n;++j){
visited[j] = 0;
}
cur = min(cur,dfs(i,1) - 1);
}
cout<<cur * 2 + n<<'\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... |