Submission #231516

#TimeUsernameProblemLanguageResultExecution timeMemory
231516Haunted_CppBosses (BOI16_bosses)C++17
100 / 100
1426 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); } } auto bfs = [&] (int source) { vis.reset (); vis[source] = 1; p[source] = -1; queue<int> q; q.push(source); 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) return (int) 1e9; vis.reset (); return dfs (source); }; int mn = 1e9; for (int i = 0; i < n; i++) { mn = min (mn, bfs (i)); } cout << mn << '\n'; return 0; }

Compilation message (stderr)

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