제출 #79522

#제출 시각아이디문제언어결과실행 시간메모리
79522combi1k1Bosses (BOI16_bosses)C++14
67 / 100
1567 ms1120 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second const int N = 5e3 + 1; vector<int> g[N]; int n, p[N]; int nCh[N]; bool vis[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1 ; i <= n ; ++i) { int s; cin >> s; while(s--) { int x; cin >> x; g[x].push_back(i); } } int ans = 1e18; for(int i = 1 ; i <= n ; ++i) { memset(vis,0,sizeof vis); memset(p,0,sizeof p); queue<int> q; q.push(i); vis[i] = 1; while(q.size()) { int u = q.front(); q.pop(); for(int v : g[u]) if(!vis[v]) { p[v] = u; q.push(v); vis[v] = 1; } } bool ch = 1; for(int j = 1 ; j <= n ; ++j) ch &= vis[j]; if (!ch) continue; int cur = 0; function<void(int)> dfs = [&](int u) { nCh[u] = 1; for(int v : g[u]) if (p[v] == u) { dfs(v); nCh[u] += nCh[v]; } cur += nCh[u]; }; dfs(i); ans = min(ans,cur); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...