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 <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include "game.h"
using namespace std;
//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007
typedef long long ll;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
const ll MAXN = 200010;
int m;
int cnt[1505][1505];
struct disj{
int pa[1505], size[1505];
void init(int n) {
for(int i=0; i<n; i++) pa[i] = i, size[i] = 1;
}
int find(int x){
return pa[x] = (pa[x] == x ? x : find(pa[x]));
}
void uni(int p, int q){
pa[q] = p;
size[p] += size[q];
}
int get_size(int x){
return size[find(x)];
}
}disj;
void initialize(int n){
m = n;
disj.init(n);
}
int hasEdge(int u, int v){
u = disj.find(u);
v = disj.find(v);
cnt[u][v]++;
cnt[v][u]++;
if(cnt[u][v] == disj.get_size(u) * disj.get_size(v)){
disj.pa[v] = u;
disj.size[u] += disj.size[v];
for (int i=0; i<m; i++) {
cnt[u][i] += cnt[v][i];
cnt[i][u] += cnt[i][v];
}
return 1;
}
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... |