제출 #621471

#제출 시각아이디문제언어결과실행 시간메모리
621471penguinhacker열쇠 (IOI21_keys)C++17
100 / 100
1171 ms50120 KiB
#include <bits/stdc++.h> using namespace std; #define ar array const int mxN=3e5; int n, m, sz[mxN], p[mxN]; vector<ar<int, 2>> adj[mxN]; bool dead[mxN], vis[mxN], has_key[mxN]; vector<int> by_color[mxN]; int find(int i) { return i^p[i]?p[i]=find(p[i]):i; } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { int n=r.size(), m=u.size(); for (int i=0; i<m; ++i) { adj[u[i]].push_back({v[i], c[i]}); adj[v[i]].push_back({u[i], c[i]}); } memset(sz, 0x3f, sizeof(sz)); iota(p, p+n, 0); while(count(dead, dead+n, 0)) { vector<ar<int, 2>> todo; for (int i=0; i<n; ++i) { if (dead[i]) continue; vector<int> cmp(1, i); vis[i]=1; int found=-1; for (int j=0; j<cmp.size()&&found==-1; ++j) { int u=cmp[j]; has_key[r[u]]=1; auto ck=[&](int v) { if (!vis[v]&&found==-1) { if (find(v)!=find(i)) found=find(v); else { cmp.push_back(v); vis[v]=1; } } }; for (int v : by_color[r[u]]) ck(v); by_color[r[u]].clear(); for (ar<int, 2> v : adj[u]) { if (has_key[v[1]]) ck(v[0]); else by_color[v[1]].push_back(v[0]); } } if (found==-1) { dead[i]=1; for (int j : cmp) sz[j]=cmp.size(); } else if (dead[found]) { dead[i]=1; } else { todo.push_back({i, found}); } for (int j : cmp) { vis[j]=0; for (ar<int, 2> v : adj[j]) by_color[v[1]].clear(); has_key[r[j]]=0; } } for (auto [u, v] : todo) { if (find(u)!=find(v)) { p[u]=v; dead[u]=1; } } } int mn=*min_element(sz, sz+n); vector<int> ans(n); for (int i=0; i<n; ++i) ans[i]=sz[i]==mn; return ans; }

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

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |    for (int j=0; j<cmp.size()&&found==-1; ++j) {
      |                  ~^~~~~~~~~~~
#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...