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 "game.h"
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
using namespace std;
set<int>cnt[2000001];
int adj[1501][1501];
int dsu[2000001],rnk[2000001];
int N;
int Find(int x){
if(dsu[x] == x) return x;
return dsu[x] = Find(dsu[x]);
}
bitset<1501> d;
void Unite(int a, int b){
a = Find(a); b = Find(b);
if(rnk[a] < rnk[b]) swap(a,b);
rnk[a] += rnk[b];
dsu[b] = a;
for(auto s: cnt[b]){
int x = Find(s);
if(d[x]) continue;
if(x == a) continue;
cnt[a].insert(x);
d[x] = 1;
adj[a][x] += adj[x][b];
adj[x][a] += adj[b][x];
}
for (auto s : cnt[b]) d[Find(s)] = 0;
}
void initialize(int n) {
N = n;
for(int i = 1; i <= n; i++) {
dsu[i] = i;
rnk[i] = 1;
}
}
int hasEdge(int u, int v) {
u++; v++;
int set_a = Find(u), set_b = Find(v);
if(set_a == set_b) return 0;
if (!adj[set_a][set_b]++) {
cnt[set_a].insert(set_b);
cnt[set_b].insert(set_a);
}
adj[set_b][set_a]++;
if(adj[set_a][set_b] != rnk[set_b] * rnk[set_a]) return 0;
if(adj[set_b][set_a] != rnk[set_a] * rnk[set_b]) return 0;
Unite(u,v);
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |