Submission #521601

#TimeUsernameProblemLanguageResultExecution timeMemory
521601eecsKeys (IOI21_keys)C++17
100 / 100
1608 ms53216 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(), mn = INT_MAX; 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), pos(n), vis(n, -1), visc(n, -1); vector<vector<int>> cand(n); iota(perm.begin(), perm.end(), 0); vector<int> cnt(n); for (int i = 0; i < n; i++) { for (auto &e : G[i]) if (e[1] == r[i]) cnt[i]++; } sort(perm.begin(), perm.end(), [&](int u, int v) { return cnt[u] < cnt[v]; }); for (int i = 0; i < n; i++) { pos[perm[i]] = i; } for (int i = 0; i < n; i++) { sort(G[i].begin(), G[i].end(), [&](array<int, 2> p, array<int, 2> q) { return pos[p[0]] < pos[q[0]]; }); } queue<int> Q; vector<bool> solved(n); vector<int> ver, col; for (int x : perm) { ver = {x}, col.clear(); while (!Q.empty()) Q.pop(); Q.push(x), vis[x] = x, solved[x] = 1; while (!Q.empty()) { int u = Q.front(); Q.pop(); if (visc[r[u]] ^ x) { for (int v : cand[r[u]]) if (vis[v] ^ x) { ver.push_back(v), Q.push(v), vis[v] = x; if (solved[v] || ver.size() > mn) goto nxt; } visc[r[u]] = x; } for (auto &e : G[u]) if (vis[e[0]] ^ x) { if (visc[e[1]] == x) { ver.push_back(e[0]), Q.push(e[0]), vis[e[0]] = x; if (solved[e[0]] || ver.size() > mn) goto nxt; } else { col.push_back(e[1]); if (solved[e[0]]) cand[e[1]].clear(); cand[e[1]].push_back(e[0]); } } } if (ver.size() < mn) mn = ver.size(), ans = ver; else copy(ver.begin(), ver.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:20: 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:38:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |      if (solved[v] || ver.size() > mn) goto nxt;
      |                       ~~~~~~~~~~~^~~~
keys.cpp:45:37: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |      if (solved[e[0]] || ver.size() > mn) goto nxt;
      |                          ~~~~~~~~~~~^~~~
keys.cpp:53:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |   if (ver.size() < mn) mn = ver.size(), ans = ver;
      |       ~~~~~~~~~~~^~~~
#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...