Submission #857857

#TimeUsernameProblemLanguageResultExecution timeMemory
857857vjudge1Bosses (BOI16_bosses)C++17
0 / 100
0 ms604 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; const long long int INF = 1e18; 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); } } long long int ans = INF; for (int i = 1; i <= n; i++) { dfs(i); long long int sum = 0; for (int j = 1; j <= n; j++) sum += val[j]; if (sum < ans) 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...