Submission #521591

#TimeUsernameProblemLanguageResultExecution timeMemory
521591eecsKeys (IOI21_keys)C++17
Compilation error
0 ms0 KiB
#include "keys.h" #include <bits/stdc++.h> using namespace std; vector<int> find_reachable(vector<int> r, vector<int> U, vector<int> V, vector<int> C) { int n = r.size(); vector<vector<array<int, 2>>> G(n); for (int i = 0; i < U.size(); i++) { G[U[i]].push_back({V[i], C[i]}); G[V[i]].push_back({U[i], C[i]}); } vector<int> ans, perm(n), vis(n, -1), visc(n, -1); vector<vector<int>> cand(n); iota(perm.begin(), perm.end(), 0); shuffle(perm.begin(), perm.end(), mt19937(time(0))); queue<int> Q; vector<bool> solved(n); vector<int> V, col; for (int x : perm) { V = {x}, col.clear(); Q.push(x), vis[x] = x, solved[x] = 1; while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto &e : G[u]) if (vis[e[0]] ^ x) { if (visc[e[1]] == x) { V.push_back(e[0]), Q.push(e[0]), vis[e[0]] = x; if (solved[e[0]] || !ans.empty() && V.size() > ans.size()) goto nxt; } else { col.push_back(e[1]), cand[e[1]].push_back(e[0]); } } if (!visc[r[u]]) { visc[r[u]] = 1; for (int v : cand[r[u]]) { V.push_back(v), Q.push(v), vis[v] = x; if (solved[v] || !ans.empty() && V.size() > ans.size()) goto nxt; } } } if (V.size() < ans.size()) ans = V; else copy(V.begin(), V.end(), back_inserter(ans)); nxt:; for (int c : col) cand[c].clear(); } vector<int> res(n); for (int x : ans) res[x] = 1; return res; }

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:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i < U.size(); i++) {
      |                     ~~^~~~~~~~~~
keys.cpp:18:17: error: declaration of 'std::vector<int> V' shadows a parameter
   18 |     vector<int> V, col;
      |                 ^
keys.cpp:5:70: note: 'std::vector<int> V' previously declared here
    5 | vector<int> find_reachable(vector<int> r, vector<int> U, vector<int> V, vector<int> C) {
      |                                                          ~~~~~~~~~~~~^
keys.cpp:27:54: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   27 |                     if (solved[e[0]] || !ans.empty() && V.size() > ans.size()) goto nxt;
      |                                         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
keys.cpp:36:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   36 |                     if (solved[v] || !ans.empty() && V.size() > ans.size()) goto nxt;
      |                                      ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~