제출 #114145

#제출 시각아이디문제언어결과실행 시간메모리
114145ahmad_salahBosses (BOI16_bosses)C++14
0 / 100
3 ms640 KiB
#include <bits/stdc++.h> using namespace std; vector<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; x--; adj[x].push_back(i); } } for (int i = 0; i < n; i++) { queue<int> q; q.push(i); memset(v, 0, sizeof v); vector<vector<int>> empty(5000); neww.swap(empty); while (!q.empty()) { int cur = q.front(); q.pop(); v[cur] = 1; for (int x : adj[cur]) if (!v[x]) neww[cur].push_back(x), q.push(x); } if (accumulate(v, v + n, 0) == 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...