Submission #986982

#TimeUsernameProblemLanguageResultExecution timeMemory
986982pedroslreyKeys (IOI21_keys)C++17
37 / 100
3019 ms27588 KiB
#include <bits/stdc++.h> #include "keys.h" using namespace std; vector<int> find_reachable(vector<int> rs, vector<int> us, vector<int> vs, vector<int> cs) { int n = rs.size(); vector<vector<pair<int, int>>> graph(n); for (int i = 0; i < us.size(); ++i) { graph[us[i]].emplace_back(vs[i], cs[i]); graph[vs[i]].emplace_back(us[i], cs[i]); } function<int (int)> test = [&graph, &rs, n](int s) { vector<vector<int>> waiting(n); vector<bool> found(n), marc(n); queue<int> q; q.push(s); int sz = 0; while (!q.empty()) { int u = q.front(); q.pop(); ++sz; if (!found[rs[u]]) { found[rs[u]] = true; for (int x: waiting[rs[u]]) if (!marc[x]) { marc[x] = true; q.push(x); } } for (auto [v, k]: graph[u]) if (!marc[v]) if (found[k]) { marc[v] = true; q.push(v); } else waiting[k].push_back(v); } return sz; }; vector<int> best{}; int val = 1e9; for (int i = 0; i < n; ++i) { int x = test(i); if (x < val) { best = vector<int>{i}; val = x; } else if (x == val) best.push_back(i); } vector<int> ans(n); for (int x: best) ans[x] = 1; return ans; }

Compilation message (stderr)

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 0; i < us.size(); ++i) {
      |                  ~~^~~~~~~~~~~
keys.cpp: In lambda function:
keys.cpp:35:35: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   35 |    for (auto [v, k]: graph[u]) if (!marc[v])
      |                                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...