제출 #617403

#제출 시각아이디문제언어결과실행 시간메모리
617403happypotato열쇠 (IOI21_keys)C++17
37 / 100
162 ms37112 KiB
#include <vector> #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define ff first #define ss second const int mxN = 3e5 + 1; vector<pii> edges[mxN]; vector<int> adj[mxN]; bool vis[mxN], key[mxN]; int val[mxN]; int dsu[mxN]; vector<int> nodes[mxN]; int n, m; void reset() { for (int i = 1; i <= n; i++) { // adj[i].clear(); vis[i] = false; key[i] = false; dsu[i] = -1; nodes[i] = {i}; } } int tar; int DSUFind(int u) { if (dsu[u] == -1) return u; return (dsu[u] = DSUFind(dsu[u])); } int DSUUnion(int u, int v) { u = DSUFind(u); v = DSUFind(v); if (nodes[u].size() < nodes[v].size()) swap(u, v); if (u != tar && v == tar) swap(u, v); if (u != v) { dsu[v] = u; if (u == tar) return v; for (int &x : nodes[v]) nodes[u].pb(x); } return 0; } int simulate(int u) { tar = u; int ans = 1; queue<int> process; process.push(u); while (!process.empty()) { int cur = process.front(); process.pop(); if (!key[val[cur]]) { for (pii edge : edges[val[cur]]) { int ret = DSUUnion(edge.ff, edge.ss); if (!ret) continue; ans += nodes[ret].size(); for (int &x : nodes[ret]) process.push(x); } key[val[cur]] = true; } } return ans; } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { n = r.size(); m = c.size(); for (int i = 0; i < n; i++) { r[i]++; } for (int i = 0; i < m; i++) { u[i]++; v[i]++; c[i]++; } for (int i = 1; i <= n; i++) { val[i] = r[i - 1]; } for (int i = 0; i < m; i++) { edges[c[i]].pb({u[i], v[i]}); } if (n <= 2000 && m <= 2000) { int dist[n + 1]; int mini = n + 1; for (int i = 1; i <= n; i++) { reset(); dist[i] = simulate(i); mini = min(mini, dist[i]); } vector<int> ans; for (int i = 1; i <= n; i++) { ans.pb(dist[i] == mini); } return ans; } return {}; }
#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...