제출 #114271

#제출 시각아이디문제언어결과실행 시간메모리
114271ahmad_salahBosses (BOI16_bosses)C++17
0 / 100
2 ms512 KiB
#include <bits/stdc++.h> using namespace std; vector<int> neww[5000]; int res; int solve(int node) { int r = 1; for (int x : neww[node]) r += solve(x); res += r; return r; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, ans = 2e9; cin >> n; vector<int> adj[n]; bool v[n]; for (int i = 0; i < n; i++) { int t; cin >> t; while (t--) { int x; cin >> x; adj[x - 1].push_back(i); } } for (int i = 0; i < n; i++) { queue<int> q; q.push(i); memset(v, 0, sizeof(v)); for (int i = 0; i < 5000; i++) neww[i].clear(); int vis = 0; while (!q.empty()) { int cur = q.front(); q.pop(); v[cur] = 1; vis++; for (int x : adj[cur]) if (!v[x]) neww[cur].push_back(x), q.push(x); } if (vis == n) { res = 0; solve(i); ans = min(ans, res); } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...