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 debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("file.txt","r",stdin );
#define outF freopen("perimeter.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define ll long long
//#define int ll
#define pii pair<int , int >
const int N = 5e3 + 5 , M = N * 4 ;
const ll MOD = 1e9 + 7 , oo = 1e9 , OO = 1e18 ;
//37
int di[] = {1 , -1 , 0 , 0};
int dj[] = {0 , 0 , 1 , -1};
int n ;
vector<int> adj[N];
int vis[N] , vid ;
int sum = 0 ;
int dfs(int i){//debug(i);
vis[i] = vid ;
int ret = 0 ;
for(auto f : adj[i]){
if(vis[f] == vid)continue ;
ret += dfs(f);
}
sum += ret + 1 ;
return ret + 1 ;
}
int32_t main()
{ // inF;
// inF;outF;
fastio;
// Dont Forget memset
cin >> n ;
int mn = oo ;
for(int i = 1 ; i <= n ; i ++){
int k ;
cin >> k ;
while(k--){
int a ;
cin >> a ;
adj[a].push_back(i);
}
}
vid ++ ;
dfs(3);
for(int i = 1 ; i <= n ; i ++){
vid ++ ;
dfs(i);
mn = min(mn , sum);
sum = 0 ;
}
cout << mn ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |