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 <vector>
#include <iostream>
using namespace std;
struct graph
{
int n;
vector<vector<bool>> adjmatrix;
vector<int> visited;
void dfs(int curr)
{
if (visited[curr]) return;
visited[curr] = true;
for (int i = 0; i < n; i++)
{
if (i == curr || !adjmatrix[curr][i]) continue;
dfs(i);
}
}
bool shouldadd(int a, int b)
{
adjmatrix[a][b] = false;
adjmatrix[b][a] = false;
visited.assign(n, false);
visited[a] = 0;
dfs(a);
bool all = true;
for (int i = 0; i < n; i++)
{
if (!visited[i]) all = false;
}
if (!all)
{
adjmatrix[a][b] = true;
adjmatrix[b][a] = true;
}
return !all;
}
};
graph g;
void initialize(int n)
{
g.n = n;
g.adjmatrix.resize(n, vector<bool>(n, true));
g.visited.resize(n, false);
}
int hasEdge(int u, int v)
{
return g.shouldadd(u, v);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |