제출 #230971

#제출 시각아이디문제언어결과실행 시간메모리
230971islingrBosses (BOI16_bosses)C++14
100 / 100
1455 ms1144 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; #define rep(i, a, b) for (auto i = (a); i < (b); ++i) #define trav(x, v) for (auto &x : v) #define eb(x...) emplace_back(x) template<class T> bool ckmin(T& a, T b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, T b) { return a < b ? a = b, 1 : 0; } constexpr int N = 10 << 9, inf = 1e9; int n, ans[N]; vector<int> g[N], gt[N]; void dfs(int u, int p) { trav(v, gt[u]) { if (v == p) continue; dfs(v, u); ans[u] += ans[v]; } } int solve(int s) { rep(u, 0, n) gt[u].clear(); vector<bool> vis(n); queue<int> q; q.push(s); vis[s] = true; while (!q.empty()) { int u = q.front(); q.pop(); trav(v, g[u]) { if (vis[v]) continue; gt[u].eb(v); q.push(v); vis[v] = true; } } rep(u, 0, n) if (!vis[u]) return inf; rep(u, 0, n) ans[u] = 1; dfs(s, s); int ret = 0; rep(u, 0, n) ret += ans[u]; return ret; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; rep(u, 0, n) { int k; cin >> k; rep(i, 0, k) { int v; cin >> v; --v; g[v].eb(u); } } int ans = inf; rep(u, 0, n) ckmin(ans, solve(u)); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...