제출 #962586

#제출 시각아이디문제언어결과실행 시간메모리
962586shezittBosses (BOI16_bosses)C++14
0 / 100
0 ms348 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <cstring> #include <queue> using namespace std; using ll = long long; #define int ll #define fore(i, a, b) for(int i=a; i<b; ++i) #define endl '\n' #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define pb push_back #define ii pair<int,int> #define vi vector<int> signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<vi> k(n); vector<vi> adj(n); fore(i, 0, n){ int tam; cin >> tam; k[i].resize(tam); fore(j, 0, tam){ cin >> k[i][j]; k[i][j]--; adj[k[i][j]].pb(i); } } int ans = 1e9; vi depth(n); fore(root, 0, n){ auto bfs = [&](int i) -> int { depth.assign(n, -1); int res = 0; queue<int> q; q.push(i); depth[i] = 1; while(sz(q)){ int cur = q.front(); q.pop(); res += depth[cur]; for(int v : adj[cur]){ if(depth[v] == -1){ depth[v] = depth[cur] + 1; q.push(v); } } } return res; }; bool ok = 1; fore(i, 0, n){ ok &= depth[i] > -1; } if(ok){ ans = min(ans, bfs(root)); } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...