Submission #1261589

#TimeUsernameProblemLanguageResultExecution timeMemory
1261589Bui_Quoc_CuongCollapse (JOI18_collapse)C++20
0 / 100
321 ms589824 KiB
#include <bits/stdc++.h> #include "collapse.h" using namespace std; #define FOR(i, a, b) for(int i = a; i <= (int)b; i++) #define FORD(i, a, b) for(int i = a; i >= (int)b; i--) #define all(a) a.begin(), a.end() #define pb push_back #define fi first #define se second const int maxN = 1e5 + 5; int n, m, q; array <int, 3> edges[maxN]; array <int, 2> Q[maxN]; // void init() { // cin >> n >> m >> q; // FOR(i, 1, m) { // cin >> edges[i][0] >> edges[i][1] >> edges[i][2]; // if (edges[i][1] > edges[i][2]) swap(edges[i][1], edges[i][2]); // } // FOR(i, 1, q) { // cin >> Q[i][0] >> Q[i][1]; // } // } namespace sub1 { bool checksub() { return max(n, q) <= 5000; } int lab[maxN]; int ssc; int find (int x) { return lab[x] < 0 ? x : lab[x] = find(lab[x]); } bool joint (int u, int v) { int x = find(u), y = find(v); if (x == y) return 0; if (lab[x] > lab[y]) swap(x, y); lab[x]+= lab[y]; lab[y] = x; ssc--; return 1; } vector <int> solve() { vector <int> res; FOR(_q, 1, q) { FOR(i, 1, n) lab[i] = - 1; ssc = n; set <pair <int, int>> edge_query; FOR(i, 1, Q[_q][0] + 1) { if (edges[i][0] == 0) { if (edge_query.find(make_pair(edges[i][0], edges[i][1])) != edge_query.end()) { edge_query.erase(edge_query.find(make_pair(edges[i][0], edges[i][1]))); } } else { if (edges[i][1] <= Q[_q][1] && edges[i][2] >= Q[_q][1] + 1) { continue; } edge_query.insert(make_pair(edges[i][1], edges[i][2])); } } for (auto &it : edge_query) joint(it.first, it.second); res.push_back(ssc); } return res; } } vector <int> simulateCollapse(int N, vector<int> T, vector<int> X, vector<int> Y, vector<int> W, vector<int> P) { n = N; m = X.size(); q = W.size(); for (int i = 0; i < m; i++) { edges[i + 1][0] = T[i]; edges[i + 1][1] = X[i]; edges[i + 2][2] = Y[i]; if (edges[i + 1][1] > edges[i + 1][2]) swap(edges[i + 1][1], edges[i + 1][2]); } for (int i = 0; i < q; i++) { Q[i + 1][0] = W[i]; Q[i + 1][1] = P[i]; } return sub1::solve(); } // void process() { // if(sub1::checksub()) sub1::solve(); // } // signed main() { // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); // #define ko "kieuoanh" // if (fopen(ko".inp", "r")) { // freopen(ko".inp", "r", stdin); // freopen(ko".out", "w", stdout); // } // init(); // process(); // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...