제출 #1108832

#제출 시각아이디문제언어결과실행 시간메모리
1108832siewjh열쇠 (IOI21_keys)C++17
100 / 100
510 ms67628 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int keya[MAXN], p[MAXN], recj[MAXN], minv, rnd; bool dead[MAXN], hask[MAXN], vis[MAXN]; vector<pair<int, int>> adj[MAXN]; vector<int> ansl, ks, pro; 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 clear(){ for (int x : ks) hask[x] = 0; for (int x : pro) vis[x] = 0; ks.clear(); pro.clear(); } void search(int st){ clear(); queue<int> q; map<int, vector<int>> lckm; q.push(st); while (!q.empty()){ int x = q.front(); q.pop(); int rx = root(x); if (rx == st){ if (vis[x]) continue; pro.push_back(x); vis[x] = 1; if (!hask[keya[x]]){ ks.push_back(keya[x]); hask[keya[x]] = 1; for (int nn : lckm[keya[x]]) q.push(nn); lckm.erase(keya[x]); } for (auto [nn, nt] : adj[x]){ if (hask[nt]) q.push(nn); else lckm[nt].push_back(nn); } } else{ join(st, rx); recj[rx] = rnd; return; } } dead[st] = 1; if (pro.size() < minv){ minv = pro.size(); ansl.clear(); for (int x : pro) ansl.push_back(x); } else if (pro.size() == minv){ for (int x : pro) ansl.push_back(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; for (rnd = 1;; rnd++){ bool run = 0; for (int i = 0; i < nodes; i++){ if (root(i) != i || dead[i] || recj[i] == rnd) continue; run = 1; search(i); } if (!run) break; } vector<int> ans(nodes, 0); for (int x : ansl) ans[x] = 1; return ans; }

컴파일 시 표준 에러 (stderr) 메시지

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