# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1016719 | n3rm1n | Game (IOI14_game) | C++17 | 0 ms | 604 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 "game.h"
using namespace std;
const int MAXN = 2e3 + 10;
int vcnt;
vector < int > g[MAXN];
unordered_set < int> s[MAXN];
void initialize(int n)
{
vcnt = n;
for (int i = 0; i < n; ++ i)
{
for (int j = 0; j < n; ++ j)
if(i != j)s[i].insert(j);
}
}
int visited[MAXN], viscnt = 0;
void dfs(int beg)
{
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 dfs0(int beg)
{
//cout << beg << endl;
visited[beg] = 1;
viscnt ++;
int nb;
for (unordered_set<int>::iterator it = s[beg].begin(); it != s[beg].end(); it ++)
{
nb = *it;
if(!visited[nb])dfs0(nb);
}
}
int f = 0;
void print_edges()
{
for (int i = 0; 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)
{
/*viscnt = 0;
memset(visited, 0, sizeof(visited));
g[u].push_back(v);
g[v].push_back(u);
dfs(0);
g[u].pop_back();
g[v].pop_back();
s[u].erase(v);
s[v].erase(u);
if(viscnt == vcnt)
{
return 0;
}*/
/* if(f)
{
//f = 1;
s[u].insert(v);
s[v].insert(u);
g[u].push_back(v);
g[v].push_back(u);
return 1;
}*/
viscnt = 0;
memset(visited, 0, sizeof(visited));
dfs0(0);
//cout << viscnt << endl;
if(viscnt != vcnt)
{
f = 1;
s[u].insert(v);
s[v].insert(u);
g[u].push_back(v);
g[v].push_back(u);
return 1;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |