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) != y && i == Find(i)) {
adj[i][p2] += adj[i][p1];
adj[p2][i] += adj[i][p1];
}
adj[i][p1] = adj[p1][i] = 0;
}
}
} 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... |