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"
using namespace std;
int p[1500], rank[1500], s[1500];
int dp[1500][1500], N;
void linkSet(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
s[x] += s[y];
for(int i = 0; i < N; i++)
dp[x][i] += dp[y][i];
}
else {
p[x] = y;
rank[y]++;
s[y] += s[x];
for(int i = 0; i < N; i++)
dp[y][i] += dp[x][i];
for(int i = 0; i < N; i++)
dp[x][i] += dp[y][i];
}
}
int findSet(int x) {
if(x != p[x])
p[x] = findSet(p[x]);
return p[x];
}
void makeSet(int x) {p[x] = x, rank[x] = 0, s[x] = 1; }
void unionSet(int x, int y) { linkSet(findSet(x), findSet(y)); }
void initialize(int n) {
N = n;
for(int i = 0; i < N; i++)
makeSet(i);
}
int hasEdge(int u, int v) {
int x = findSet(u);
int y = findSet(v);
if(x == y) return 0;
if(dp[x][y] == s[x]*s[y]-1) {
unionSet(x, y);
return 1;
}
dp[x][y]++;
dp[y][x]++;
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... |