This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
#ifndef _GAME_H
#define _GAME_H
void initialize(int n);
int hasEdge(int u, int v);
#include <cstdio>
#include <cassert>
#include "game.h"
int read_int() {
int x;
assert(scanf("%d", &x) == 1);
return x;
}
int main() {
int n, u, v;
n = read_int();
initialize(n);
for (int i = 0; i < n * (n - 1) / 2; i++) {
u = read_int();
v = read_int();
printf("%d\n", hasEdge(u, v));
}
return 0;
}
#endif
#else
#include "game.h"
#endif
#include <bits/stdc++.h>
const int mxN = 1500;
int s[mxN][mxN];
int n;
std::vector<int> r[mxN];
int f[mxN];
void initialize(int _n) {
n = _n;
for (int i = 0; i < n; i++) {
r[i].push_back(i);
f[i] = i;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) s[i][j] = 1;
}
}
}
int hasEdge(int u, int v) {
// let's delete this
s[f[u]][f[v]]--;
if (s[f[u]][f[v]] >= 1) {
return 0;
}
// we move em
// move from one to another
int a = f[u], b = f[v];
for (int i : r[b]) {
r[a].push_back(i);
f[i] = a;
}
for (int i = 0; i < n; i++) {
s[a][i] += s[b][i];
}
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... |