제출 #717564

#제출 시각아이디문제언어결과실행 시간메모리
717564vjudge1Bosses (BOI16_bosses)C++11
0 / 100
1 ms468 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int #define inf 1e15 #define endl '\n'; using pii = pair<int,int>; using piii = pair<int,pii>; using piiii = pair<pii,pii>; int mod = 1e9+7; vector<int>g[5005]; int cnt[5005]; int vis[5005]; void dfs(int node , int par) { cnt[node] = cnt[par]+1; vis[node] = 1; for(auto it : g[node]) { if(!vis[it]) { dfs(it , node); } } } int32_t main() { //freopen("file.in" , "r" , stdin);freopen("file.out" , "w" , stdout); ios_base::sync_with_stdio(0);cin.tie(0); int n; cin >> n; for(int i=1 ; i<=n ; i++) { int m; cin >> m; while(m--) { int x; cin >> x; g[x].push_back(i); } } int sum , ans=INT_MAX; for(int i=1 ; i<=n ; i++) { sum=0; memset(cnt , 0 , sizeof(cnt)); memset(vis , 0 , sizeof(vis)); dfs(i,0); for(int i=1 ; i<=n ; i++) { sum+=cnt[i]; } ans = min(ans , sum); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...