# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
257808 | Bruteforceman | Making Friends on Joitter is Fun (JOI20_joitter2) | C++11 | 5068 ms | 22560 KiB |
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 <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
set <int> in[maxn], out[maxn];
set <pair <int, int>> incoming[maxn], outgoing[maxn];
queue <pair <int, int>> Q;
int par[maxn];
int sub[maxn];
int root(int x) {
if(par[x] == x) return x;
return par[x] = root(par[x]);
}
bool change(set <int> &t, set <int> &r, int i, int j) {
t.erase(i); t.insert(j);
return r.count(j);
}
void join(int x, int y) {
x = root(x);
y = root(y);
if(incoming[x].size() + outgoing[x].size() > incoming[y].size() + outgoing[y].size()) swap(x, y);
if(x != y) {
for(int i : in[x]) {
in[y].insert(i);
if(change(out[i], in[i], x, y)) Q.emplace(i, y);
}
for(int i : out[x]) {
out[y].insert(i);
if(change(in[i], out[i], x, y)) Q.emplace(i, y);
}
for(auto i : incoming[x]) {
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |