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>
#ifndef _DEBUG
#include "game.h"
#endif
using namespace std;
vector<int> parent; // logn union find
vector<vector<int>> queried;
int n;
int find(int a)
{
if (parent[a] == a)
return a;
return parent[a] = find(parent[a]);
}
void initialize(int n)
{
::n = n;
parent = vector<int>(n);
queried = vector<vector<int>>(n, vector<int>(n));
for (int i = 0; i < n; i++)
{
parent[i] = i;
}
}
int hasEdge(int u, int v)
{
queried[u][v] = 1;
queried[v][u] = 1;
int U = find(u);
int V = find(v);
if (U > V)
swap(U, V), swap(u, v);
bool a = U == 0;
int b = V == 0;
if (a ^ b)
{
for (int i = 0; i < n; i++) // only insert edge if last query to group zero
if (find(i) == 0 && !queried[v][u])
return 0;
parent[V] = 0;
assert(U == 0);
return 1;
}
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... |