Submission #546746

#TimeUsernameProblemLanguageResultExecution timeMemory
546746JomnoiBosses (BOI16_bosses)C++17
100 / 100
743 ms648 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int MAX_N = 5e3 + 10; const long long INF = 1e18 + 7; vector <int> adj[MAX_N]; bitset <MAX_N> visited; int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; for(int i = 1; i <= n; i++) { int k; cin >> k; while(k--) { int p; cin >> p; adj[p].push_back(i); } } long long ans = INF; for(int i = 1; i <= n; i++) { visited = 0; long long sum = 0; visited[i] = true; queue <pair <int, int>> q; q.emplace(i, 1); while(!q.empty()) { auto [u, c] = q.front(); q.pop(); sum += c; for(auto v : adj[u]) { if(visited[v] == false) { visited[v] = true; q.emplace(v, c + 1); } } } if(visited.count() == n) { ans = min(ans, sum); } } cout << ans; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:46:28: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         if(visited.count() == n) {
      |            ~~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...