# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
290407 | AaronNaidu | Game (IOI14_game) | C++14 | 0 ms | 0 KiB |
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 "grader.h"
using namespace std;
vector<int> graph[2000];
bool asked[2000][2000];
bool answer[2000][2000];
int n, edgeCount;
int hasEdge(int u, int v) {
if (edgeCount == n-2)
{
asked[u][v] = true;
asked[v][u] = true;
return 0;
}
if (graph[u].size() == 0 and graph[v].size() == 0)
{
graph[u].push_back(v);
graph[v].push_back(u);
asked[u][v] = true;
asked[v][u] = true;
answer[u][v] = true;
answer[v][u] = true;
edgeCount++;
return 1;
}
if (graph[u].size() >= 2 and graph[v].size() >= 2)
{
asked[u][v] = true;
asked[v][u] = true;
return 0;
}
if (graph[u].size() >= 1)
{
/*for (int i = 0; i < n; i++)
{
if (i != v and i != u and !asked[i][u])
{
asked[u][v] = true;
asked[v][u] = true;
return 0;
}
}*/
for (auto j : graph[u])
{
if (!asked[j][v])
{
asked[u][v] = true;
asked[v][u] = true;
return 0;
}
}
}
if (graph[v].size() >= 1)
{
/*for (int i = 0; i < n; i++)
{
if (i != u and i != v and !asked[i][v])
{
asked[u][v] = true;
asked[v][u] = true;
return 0;
}
}*/
for (auto j : graph[v])
{
if (!asked[j][u])
{
asked[u][v] = true;
asked[v][u] = true;
return 0;
}
}
}
graph[v].push_back(u);
graph[u].push_back(v);
asked[u][v] = true;
answer[u][v] = true;
asked[v][u] = true;
answer[v][u] = true;
edgeCount++;
return 1;
}
void initialize(int N) {
n = N;
edgeCount = 0;
}