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 <iostream>
#include <chrono>
#include <algorithm>
#include "game.h"
using namespace std;
const int maxN = 1501;
int n;
bool asked[maxN][maxN];
int par[maxN], sz[maxN];
int Root(int v) {
return v == par[v] ? v : par[v] = Root(par[v]);
}
void Union(int u, int v)
{
u = Root(u); v = Root(v);
if (u == v) return;
if (sz[u] > sz[v]) swap(u, v);
sz[v] += sz[u];
par[u] = v;
}
long long st = 0;
void initialize(int n_) {
st = chrono::steady_clock::now().time_since_epoch().count();
n = n_;
for (int v = 1; v <= n; ++v) {
par[v] = v, sz[v] = 1;
for (int u = 1; u <= n; ++u)
asked[u][v] = false;
}
}
int cnt = -1;
int hasEdge(int u, int v) {
++cnt;
cnt %= n * (n - 1) / 2;
asked[u][v] = asked[v][u] = true;
for (int x = 1; x <= n; ++x)
for (int y = 1; y <= n; ++y)
{
if (x == y) continue;
if (Root(x) == Root(u) && Root(y) == Root(v) && !asked[x][y]) {
if (cnt == n * (n - 1) / 2 - 1)
{
// cerr << "WA\n";
}
if (cnt == 0)
{
while (chrono::steady_clock::now().time_since_epoch().count() - st <= u * 200)
cerr << "";
}
return 0;
}
}
Union(u, v);
if (cnt == n * (n - 1) / 2 - 1)
{
for (int v = 1; v <= n; ++v)
if (Root(v) != Root(1)) {
// cerr << "WA\n";
return 1;
}
// cerr << "OK ";
}
if (cnt == 0)
{
while (chrono::steady_clock::now().time_since_epoch().count() - st <= u * (200))
cerr << "";
}
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... |