Submission #621442

#TimeUsernameProblemLanguageResultExecution timeMemory
621442penguinhackerKeys (IOI21_keys)C++17
9 / 100
255 ms50032 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]; 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]; for (ar<int, 2> v : adj[u]) by_color[v[1]].push_back(v[0]); for (int v : by_color[r[u]]) if (!vis[v]) { if (find(v)!=find(i)) { found=find(v); break; } cmp.push_back(v); vis[v]=1; } by_color[r[u]].clear(); } 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(); } } //cout << "ITERATION" << endl; for (auto [u, v] : todo) { if (find(u)!=find(v)) { //cout << u << " " << v << endl; 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; }

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: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...