제출 #373920

#제출 시각아이디문제언어결과실행 시간메모리
373920Aryan_RainaBosses (BOI16_bosses)C++14
0 / 100
1 ms492 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ar array const int INF = 1e15; const int MOD = 1e9+7; const int MXN = 5005; vector<int> g[MXN]; int n; int bfs(int rt) { vector<bool> vis(n, 0); queue<int> q; vector<ar<int,2>> ch[n]; q.push(rt); vis[rt] = 1; auto nextLayer = [&](int u) { int lol = 0; for (int v : g[u]) if (!vis[v]) lol++; return lol; }; while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) if (!vis[v]) { ch[u].push_back({nextLayer(v), v}); vis[v] = 1; } sort(ch[u].begin(), ch[u].end()); for (auto v : ch[u]) q.push(v[1]); } int ans = 0; function<int(int)> dfs = [&](int u) { int cur = 1; for (ar<int,2> v : ch[u]) { cur += dfs(v[1]); } ans += cur; return cur; }; dfs(rt); return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for (int i = 0; i < n; i++) { int x; cin>>x; while (x--) { int j; cin>>j; --j; g[j].push_back(i); } } int ans = INF; for (int i = 0; i < n; i++) ans = min(ans, bfs(i)); cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...