# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
216728 | ainta | Making Friends on Joitter is Fun (JOI20_joitter2) | C++17 | 2257 ms | 121324 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<cstdio>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#define N_ 101000
using namespace std;
int n, m, UF[N_];
long long res, InD[N_];
map<int, int>Out[N_], In[N_];
vector<int>G[N_];
set<int>E[N_], F[N_];
int Find(int a) {
if (a == UF[a])return a;
return UF[a] = Find(UF[a]);
}
void Merge(int a, int b) {
if (Find(a) == Find(b))return;
int pa = Find(a), pb = Find(b);
int nd = InD[pa] + InD[pb] - Out[pb][pa] - Out[pa][pb];
res += 1ll * (G[pa].size() + G[pb].size()) * nd + 1ll * G[pa].size()*G[pb].size() * 2;
res -= 1ll * InD[pb] * G[pb].size();
res -= 1ll * InD[pa] * G[pa].size();
if (G[pa].size() + In[pa].size() + Out[pa].size() + F[pa].size() < G[pb].size() + In[pb].size() + Out[pb].size() + F[pb].size())swap(pa, pb);
InD[pa] = nd;
In[pb].erase(pa);
Out[pb].erase(pa);
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... |