# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382282 | couplefire | Making Friends on Joitter is Fun (JOI20_joitter2) | C++17 | 1099 ms | 73244 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 pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5 + 10;
set<int> in[N], out[N], com[N], e[N];
long long ans;
long long par[N], sz[N];
int n, m;
int find( int u ) { return par[u] == u ? u : par[u] = find( par[u] ); }
long long cal( int u ) { return 1LL * ( ( ( int )e[u].size() - sz[u] ) * sz[u] ) + 1LL * sz[u] * ( sz[u]-1 ); }
void merge( int a, int b ) {
vector<pii> v;
a = find( a ), b = find( b );
if( a == b ) return ;
if( in[a].size() + out[a].size() + e[a].size() < in[b].size() + out[b].size() + e[b].size() ) swap( a, b );
ans -= cal( a ), ans -= cal( b );
in[a].erase( b ), in[b].erase( a ), out[a].erase( b ), out[b].erase( a );
for( int x : in[b] ) {
if( out[a].count( x ) ) v.emplace_back( x, a );
out[x].erase( b ), out[x].emplace( a );
}
for( int x : out[b] ) {
if( in[a].count( x ) ) v.emplace_back( x, 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... |