Submission #857856

#TimeUsernameProblemLanguageResultExecution timeMemory
857856vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 5005, INF = 1e9; int n, mark[maxn], val[maxn]; vector<int> ad[maxn]; void dfs(int v) { mark[v] = 1; for (int u: ad[v]) { if (!mark[u]) { dfs(u); val[v] += val[u]; } } val[v]++; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for (int i = 1; i <= n; i++) { int t; cin >> t; for (int j = 1; j <= t; j++) { int x; cin >> x; ad[x].push_back(i); } } int ans = INF; for (int i = 1; i <= n; i++) { dfs(i); int sum = 0; for (int i = 1; i <= n; i++) sum += val[i]; ans = min(ans, sum); memset(val, 0, sizeof val); memset(mark, 0, sizeof mark); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...