Submission #231519

#TimeUsernameProblemLanguageResultExecution timeMemory
231519Haunted_CppBosses (BOI16_bosses)C++17
67 / 100
1519 ms888 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; vector< vector<int> > g (N); int p [N]; bitset<N> vis; int subtree [N]; int dfs (int node) { int sum = 0; subtree[node] = 1; int res = 0; for (auto to : g[node]) { if (p[to] == node) { res += dfs (to); sum += subtree[to]; } } subtree[node] += sum; return res + subtree[node]; } int main () { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int st; cin >> st; --st; g[st].emplace_back(i); } } int mn = 1e9; for (int i = 0; i < n; i++) { vis.reset (); vis[i] = 1; p[i] = -1; queue<int> q; q.push(i); while (!q.empty()) { int node = q.front(); q.pop(); for (auto to : g[node]) { if (!vis[to]) { vis[to] = 1; p[to] = node; q.push(to); } } } if (vis.count() != n) continue; vis.reset (); mn = min (mn, dfs (i)); } cout << mn << '\n'; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:60:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (vis.count() != n) continue;
         ~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...