This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "collapse.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> brute(int n, vector<int> t, vector<int> x, vector<int> y, vector<int> w, vector<int> p) {
int m = (int)t.size();
int q = (int)w.size();
for (int i = 0; i < m; i++) {
if (x[i] > y[i]) {
swap(x[i], y[i]);
assert(0 <= x[i] && x[i] < y[i] && y[i] < n);
}
}
assert((int) t.size() == m);
assert((int) x.size() == m);
assert((int) y.size() == m);
assert((int) w.size() == q);
assert((int) p.size() == q);
vector<int> sol((int) w.size());
for (int iq = 0; iq < (int) w.size(); iq++) {
set<pair<int, int>> s;
for (int i = 0; i <= w[iq]; i++) {
pair<int, int> cur = make_pair(x[i], y[i]);
if (s.count(cur)) {
s.erase(cur);
} else {
s.insert(cur);
}
}
vector<pair<int, int>> ve;
for (auto &it : s) {
if (it.first <= p[iq] && it.second > p[iq]) {
continue;
}
ve.push_back(it);
}
vector<int> t(n);
iota(t.begin(), t.end(), 0);
int comps = n;
function<int(int)> getpap = [&] (int a) {
if (t[a] == a) {
return a;
} else {
return t[a] = getpap(t[a]);
}
};
function<void(int, int)> unite = [&] (int a, int b) {
a = getpap(a);
b = getpap(b);
if (a != b) {
comps--;
t[a] = b;
}
};
for (auto &it : ve) {
unite(it.first, it.second);
}
sol[iq] = comps;
}
return sol;
}
vector<int> simulateCollapse(int N, vector<int> T, vector<int> X, vector<int> Y, vector<int> W, vector<int> P) {
return brute(N,T,X,Y,W,P);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |