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"
#include "game.h"
using namespace std;
using ll = long long;
const int maxn=1505;
int p[maxn],sz[maxn];
unordered_map<int,int>m[maxn];
void initialize(int n) {
for(int i = 0;i < n;i++){
p[i] = i;
sz[i] = 1;
}
}
int ata(int x){
if(p[x] == x) return x;
return p[x] = ata(p[x]);
}
int hasEdge(int u, int v) {
u = ata(u);
v = ata(v);
if((int)m[u].size() < (int)m[v].size()) swap(u,v);
int now = 0;
if(m[v].find(u) != m[v].end()) now = m[v][u];
if(now == sz[u] * sz[v] - 1){
for(auto j : m[v]){
if(j.first == u) continue;
m[u][j.first] += j.second;
if(m[j.first].find(v) != m[j.first].end()) m[j.first].erase(v);
m[j.first][u] += j.second;
}
m[v].clear();
if(m[u].find(v) != m[u].end()) m[u].erase(v);
p[v] = u;
sz[u] += sz[v];
sz[v] = 0;
return 1;
}
m[u][v]++;
m[v][u]++;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |