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>
#include "game.h"
using namespace std;
vector<vector<int>> adjmatrix(0);
void initialize(int n)
{
adjmatrix.assign(n, vector<int> (n, -1));
for(int i = 0; i < n; i++)
{
adjmatrix[i][i] = 0;
}
}
void dfs(int i, vector<vector<int>>& adjlist, vector<bool>& visited)
{
visited[i] = true;
for(int j : adjlist[i])
{
if(!visited[j])
{
dfs(j, adjlist, visited);
}
}
}
int hasEdge(int u, int v)
{
int n = adjmatrix.size();
vector<vector<int>> adjlist(n, vector<int> (0));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(adjmatrix[i][j] == 1 || ((min(i, j) != min(u, v) || max(i, j) != max(u, v)) && adjmatrix[i][j] == -1))
{
adjlist[i].push_back(j);
}
}
}
vector<bool> visited(n, false);
dfs(0, adjlist, visited);
if(find(visited.begin(), visited.end(), false) != visited.end())
{
adjmatrix[u][v] = 1;
adjmatrix[v][u] = 1;
return 1;
}
adjmatrix[u][v] = 0;
adjmatrix[v][u] = 0;
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... |