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"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
vector<int> pa;
vector<vector<bool> > w;
vector<bool> wh;
int N;
int dfs(int i)
{
int s = 1;
random_shuffle(v[i].begin(), v[i].end());
for (auto h : v[i])
{
if (!wh[h] && w[i][h])
{
pa[h] = i;
wh[h] = 1;
s += dfs(h);
}
}
return s;
}
void initialize(int n)
{
int i, j;
N = n;
v.resize(n);
pa.resize(n);
w.resize(n);
wh.resize(n);
for (i = 0; i < n; i++)
{
w[i].resize(n);
for (j = 0; j < n; j++)
{
if (j == i)
w[i][j] = 0;
else
{
w[i][j] = 1;
v[i].push_back(j);
}
}
}
for (i = 0; i < n; i++)
wh[i] = 0;
wh[0] = 1;
pa[0] = 0;
dfs(0);
}
int hasEdge(int u, int v)
{
w[u][v] = w[v][u] = 0;
if (pa[u] != v && pa[v] != u)
return 0;
int s = 0;
s = rand() % N;
for (int i = 0; i < N; i++)
wh[i] = 0;
wh[s] = 1;
pa[s] = s;
if (dfs(s) == N)
return 0;
w[u][v] = w[v][u] = 1;
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... |