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;
int pred[1510];
int step[1510];
int find(int v) {
if (pred[v] == v)return v;
return pred[v] = find(pred[v]);
}
void make(int v, int n) {
pred[v] = v;
step[v] = n - 1;
return;
}
void merge(int a, int b) {
a = find(a);
b = find(b);
if (a == b)return;
step[a] += step[b];
pred[b] = a;
}
int was[1510][1510];
int N;
void initialize(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
was[i][j] = -1;
}
was[i][i] = 0;
}
for (int i = 1; i <= n; i++)
make(i, n);
N = n;
}
int hasEdge(int u, int v) {
u++; v++;
if (was[u][v] != -1) return was[u][v];
if (step[find(u)] <= 1 || step[find(v)] <= 1) {
was[u][v] = 1; was[v][u] = 1;
merge(u, v);
step[find(u)]--;
step[find(v)]--;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (was[i][j] != -1)continue;
if (find(i) != find(j))continue;
was[i][j] = 0; was[j][i] = 0;
step[find(i)] -= 2;
}
}
return 1;
}
was[u][v] = 0; was[v][u] = 0;
step[find(u)]--;
step[find(v)]--;
return 0;
}
/**
4
0 3
1 0
0 2
3 1
1 2
2 3
4
0 3
2 0
0 1
1 2
1 3
2 3
4
0 1
3 0
1 2
0 2
3 1
2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |