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;
const int MAXN = 2e3 + 10;
int vcnt;
int used[MAXN][MAXN];
vector < int > g[MAXN];
void initialize(int n)
{
vcnt = n;
}
int visited[MAXN], viscnt = 0;
void dfs(int beg)
{
// cout << "* " << beg << endl;
visited[beg] = 1;
viscnt ++;
int nb;
for (int i = 0; i < g[beg].size(); ++ i)
{
nb = g[beg][i];
if(!visited[nb])dfs(nb);
}
}
void print_edges()
{
for (int i = 1; i < vcnt; ++ i)
{
cout << "for " << i << endl;
for (int j = 0; j < g[i].size(); ++ j)
cout << g[i][j] << " ";
cout << endl;
}
}
int hasEdge(int u, int v)
{
//cout << vcnt << endl;
viscnt = 0;
memset(visited, 0, sizeof(visited));
g[u].push_back(v);
g[v].push_back(u);
// print_edges();
// cout << " -- " << endl;
// cout << "starting a dfs" << endl;
dfs(0);
// cout << " -- " << endl;
// cout << "after connecting = "<< viscnt << endl;
if(viscnt == vcnt) /// svyrzva
{
g[u].pop_back();
g[v].pop_back();
/// print_edges();
return 0;
}
g[u].pop_back();
g[v].pop_back();
for (int i = 0; i < vcnt; ++ i)
{
for (int j = i+1; j < vcnt; ++ j)
{
if(!used[i][j] && !(i == min(u, v) && j == (max(u, v))))
{
g[i].push_back(j);
g[j].push_back(i);
}
}
}
viscnt = 0;
memset(visited, 0, sizeof(visited));
dfs(0);
for (int i = 0; i < vcnt; ++ i)
{
vector < int > neww;
while(g[i].size())
{
int nb = g[i].back();
if(used[i][nb])break;
g[i].pop_back();
}
}
if(viscnt != vcnt)
{
used[u][v] = 1;
used[v][u] = 1;
g[u].push_back(v);
g[v].push_back(u);
// print_edges();
return 1;
}
g[u].push_back(v);
g[v].push_back(u);
used[u][v] = 1;
used[v][u] = 1;
//print_edges();
return 1;
}
Compilation message (stderr)
game.cpp: In function 'void dfs(int)':
game.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < g[beg].size(); ++ i)
| ~~^~~~~~~~~~~~~~~
game.cpp: In function 'void print_edges()':
game.cpp:31:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int j = 0; j < g[i].size(); ++ j)
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |