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 <iostream>
#define MAXN 1505
using namespace std;
int Cmp, N, adj[MAXN][MAXN];
class DSU {
public:
int Set[MAXN];
void init(int n) {
for (int i=0; i<=n; i++) {Set[i] = i;}
}
int Find(int x) {
return(Set[x] == x ? x : Set[x] = Find(Set[x]));
}
void Union(int x, int y) {
int p1 = Find(x), p2 = Find(y);
Set[p1] = p2;
for (int i=0; i<N; i++) {
if (Find(i) != x && i == Find(i)) {
adj[i][y] += adj[i][x];
adj[y][i] += adj[i][x];
}
}
}
} UF;
void initialize(int n) {
UF.init(n), N=n;
Cmp = N;
for (int i=0; i<N; i++) {
for (int j=i+1; j<N; j++) {
adj[i][j]=adj[j][i] = 1;
}
}
}
int hasEdge(int u, int v) {
int p1 = UF.Find(u), p2 = UF.Find(v);
if (p1 == p2) {return(1);}
adj[p1][p2]--, adj[p2][p1]--;
if (adj[p1][p2]) {
return(0);
}
UF.Union(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... |