Submission #813370

#TimeUsernameProblemLanguageResultExecution timeMemory
813370SteGGBosses (BOI16_bosses)C++17
100 / 100
1118 ms980 KiB
#include <bits/stdc++.h> #define int long long using namespace std; void open(){ if(fopen("input.inp", "r")){ freopen("input.inp", "r", stdin); // freopen("output.out", "w", stdout); } } const int inf = 3e18; const int maxn = 5005; int n; vector<int> candidate[maxn]; vector<int> tr[maxn]; bool check[maxn]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); open(); cin >> n; for(int i = 1; i <= n; i++){ int k; cin >> k; for(int j = 1; j <= k; j++){ int a; cin >> a; candidate[a].push_back(i); } } int result; int last_result = inf; auto dfs = [&](auto &&dfs, int u) -> int { int sz = 1; for(int v : tr[u]){ sz += dfs(dfs, v); } result += sz; return sz; }; for(int root = 1; root <= n; root++){ memset(check, false, sizeof(check)); for(int i = 0; i <= n; i++){ tr[i].clear(); } queue<pair<int, int>> q; q.push({root, 0}); int cnt = 0; while(!q.empty()){ int u = q.front().first; int p = q.front().second; q.pop(); if(check[u]) continue; cnt++; check[u] = true; tr[p].push_back(u); for(int v : candidate[u]){ if(check[v]) continue; q.push({v, u}); } } if(cnt < n) continue; result = 0; dfs(dfs, root); last_result = min(result, last_result); } cout << last_result << endl; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'void open()':
bosses.cpp:8:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   freopen("input.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...