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;
typedef long long ll;
int n;
int par[1502];
int cnt[1502];
int sum[1502];
int queryCount;
int find(int x){
if(x==par[x]) return x;
return par[x] = find(par[x]);
}
void merge(int x, int y){
sum[find(x)] -= y, sum[find(y)] -= x;
x = find(x), y = find(y);
cnt[x]--, cnt[y]--;
par[x] = y;
sum[y] += sum[x];
cnt[y] += cnt[x];
sum[x] = cnt[x] = 0;
}
void initialize(int N){
n = N;
for(int i=0; i<n; i++) par[i] = i;
for(int i=0; i<n; i++) cnt[i] = n-1, sum[i] = n*(n-1)/2 - i;
}
int hasEdge(int u, int v){
queryCount++;
if(find(u)==find(v)) return true;
cnt[find(u)]--, cnt[find(v)]--;
sum[find(u)]-=v, sum[find(v)]-=u;
u = find(u), v = find(v);
while(cnt[u] == 1){
merge(u, sum[u]);
u = find(u);
}
while(cnt[v] == 1){
merge(v, sum[v]);
v = find(v);
}
return false;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |