# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211887 | PeppaPig | Making Friends on Joitter is Fun (JOI20_joitter2) | C++14 | 1094 ms | 64248 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>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5+5;
int n, m, par[N], sz[N];
set<int> in[N], out[N], E[N];
long ans;
void update(int x, int sign) { ans += sign * (1ll * (E[x].size() - sz[x]) * sz[x] + 1ll * sz[x] * (sz[x] - 1)); }
int find(int x) { return x == par[x] ? x : find(par[x]); }
queue<pii> Q;
void unite(int a, int b) {
a = find(a), b = find(b);
if(a == b) return;
update(a, -1), update(b, -1);
if(in[a].size() + out[a].size() + E[a].size() > in[b].size() + out[b].size() + E[b].size())
swap(a, b);
in[a].erase(b), out[a].erase(b);
in[b].erase(a), out[b].erase(a);
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... |