This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// this is literally a 24-liner
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
int cnt[1505][1505], par[1505], sz[1505];
int ufds(int x) {return par[x]=(par[x]==x?x:ufds(par[x]));}
void add(int u, int v) {
u = ufds(u), v = ufds(v);
if(sz[u]>sz[v]) swap(u,v);
sz[v] += sz[u];
par[u] = v;
for(int i=0;i<1505;i++) cnt[v][i]=(cnt[i][v]+=cnt[i][u]);
}
void initialize(int n) {
iota(par,par+1505,0);
fill(sz,sz+1505,1);
}
int hasEdge(int u, int v) {
u = ufds(u); v = ufds(v);
if(u==v) return 0;
cnt[u][v]++; cnt[v][u]++;
if(cnt[u][v]==sz[u]*sz[v]) {add(u,v); return 1;}
else 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... |