Submission #1108830

#TimeUsernameProblemLanguageResultExecution timeMemory
1108830siewjhKeys (IOI21_keys)C++17
100 / 100
1633 ms73648 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int keya[MAXN], p[MAXN], minv; bool dead[MAXN]; vector<pair<int, int>> adj[MAXN]; set<int> ansl, recj; int root(int x){ if (p[x] == -1) return x; else return p[x] = root(p[x]); } void join(int ra, int rb){ p[ra] = rb; } void search(int st){ queue<int> q; map<int, vector<int>> lckm; set<int> ks, pro; q.push(st); while (!q.empty()){ int x = q.front(); q.pop(); int rx = root(x); if (rx == st){ if (pro.count(x)) continue; pro.insert(x); if (!ks.count(keya[x])){ ks.insert(keya[x]); for (int nn : lckm[keya[x]]) q.push(nn); lckm.erase(keya[x]); } for (auto [nn, nt] : adj[x]){ if (ks.count(nt)) q.push(nn); else lckm[nt].push_back(nn); } } else{ join(st, rx); recj.insert(rx); return; } } dead[st] = 1; if (pro.size() < minv){ minv = pro.size(); ansl.clear(); for (int x : pro) ansl.insert(x); } else if (pro.size() == minv){ for (int x : pro) ansl.insert(x); } } vector<int> find_reachable(vector<int> key, vector<int> u, vector<int> v, vector<int> lock){ int nodes = key.size(), edges = lock.size(); for (int i = 0; i < nodes; i++){ keya[i] = key[i]; p[i] = -1; } for (int i = 0; i < edges; i++){ int a = u[i], b = v[i], c = lock[i]; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } minv = MAXN; while (true){ bool run = 0; recj.clear(); for (int i = 0; i < nodes; i++){ if (root(i) != i || dead[i] || recj.count(i)) continue; run = 1; search(i); } if (!run) break; } vector<int> ans(nodes, 0); for (int x : ansl) ans[x] = 1; return ans; }

Compilation message (stderr)

keys.cpp: In function 'void search(int)':
keys.cpp:41:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |  if (pro.size() < minv){
      |      ~~~~~~~~~~~^~~~~~
keys.cpp:46:22: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |  else if (pro.size() == minv){
      |           ~~~~~~~~~~~^~~~~~~
#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...