Submission #823733

#TimeUsernameProblemLanguageResultExecution timeMemory
823733becaidoKeys (IOI21_keys)C++17
100 / 100
1742 ms67588 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "keys.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int SIZE = 3e5 + 5; int n; int r[SIZE], a[SIZE]; vector<pair<int, int>> adj[SIZE]; int to[SIZE]; int dsu(int x) { return x == to[x] ? x : (to[x] = dsu(to[x])); } vector<int> deal(int s, bool is = 0) { unordered_set<int> us, vs; unordered_map<int, vector<int>> mp; queue<int> q; q.push(s); vs.insert(s); while (q.size()) { int pos = q.front(); q.pop(); if (!us.count(r[pos])) { us.insert(r[pos]); for (int x : mp[r[pos]]) { if (dsu(x) != s) return vector<int>(1, dsu(x)); q.push(x); vs.insert(x); } mp[r[pos]].clear(); } for (auto [np, c] : adj[pos]) if (!vs.count(np)) { if (us.count(c)) { if (dsu(np) != s) return vector<int>(1, dsu(np)); q.push(np); vs.insert(np); } else { mp[c].emplace_back(np); } } } if (!is) return vector<int>(1, -1); vector<int> all; for (int x : vs) all.pb(x); return all; } vector<int> find_reachable(vector<int> _r, vector<int> u, vector<int> v, vector<int> c) { n = _r.size(); FOR (i, 0, n - 1) { r[i] = _r[i]; to[i] = i; } FOR (i, 0, u.size() - 1) { adj[u[i]].pb(v[i], c[i]); adj[v[i]].pb(u[i], c[i]); } while (true) { FOR (i, 0, n - 1) if (dsu(i) == i) a[i] = deal(i)[0]; bool f = 0; FOR (i, 0, n - 1) if (dsu(i) == i && a[i] != -1) { to[i] = dsu(a[i]); f = 1; } if (!f) break; } int mn = n + 1; vector<int> ansp, ans(n); FOR (i, 0, n - 1) if (dsu(i) == i) { auto v = deal(i, 1); if (v.size() < mn) { mn = v.size(); ansp.clear(); } if (v.size() == mn) ansp.insert(ansp.end(), v.begin(), v.end()); } for (int x : ansp) ans[x] = 1; return ans; } #ifdef WAIMAI int main() { int n, m; assert(2 == scanf("%d%d", &n, &m)); vector<int> r(n), u(m), v(m), c(m); for(int i=0; i<n; i++) { assert(1 == scanf("%d", &r[i])); } for(int i=0; i<m; i++) { assert(3 == scanf("%d %d %d", &u[i], &v[i], &c[i])); } vector<int> ans = find_reachable(r, u, v, c); for (int i = 0; i < (int) ans.size(); ++i) { if(i) putchar(' '); putchar(ans[i]+'0'); } printf("\n"); return 0; } #endif

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:94:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   94 |         if (v.size() < mn) {
      |             ~~~~~~~~~^~~~
keys.cpp:98:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   98 |         if (v.size() == mn) ansp.insert(ansp.end(), v.begin(), v.end());
      |             ~~~~~~~~~^~~~~
#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...