제출 #723773

#제출 시각아이디문제언어결과실행 시간메모리
723773yahyobekabdunazarovBosses (BOI16_bosses)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main(){ int n; cin >> n; vector<int> adj[n + 1]; for(int i = 0; i < n; i++){ int x; cin >> x; for(int j = 0; j < x; j++){ int a; cin >> a; adj[a].push_back(i + 1); } } int mn = INT_MAX; for(int i = 1; i <= n; i++){ vector<int> used(n + 1), d(n + 1, 1), p(n + 1); queue<int> q; q.push(i); used[i] = 1; p[i] = -1; while(!q.empty()){ int v = q.front(); q.pop(); for(int u: adj[v]){ if(!used[u]){ used[u] = true; q.push(u); d[u] = d[v] + 1; p[u] = v; } } } int sum = 0; for(int i = 1; i <= n; i++){ sum += d[i]; } for(int i = 1; i <= n; i++){ if(!used[i]) continue; } mn = min(sum, mn); fill(used.begin(), used.end(), 0); } cout << mn; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...