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 <bits/stdc++.h>
using namespace std;
const int maxn = 1510;
int n;
int used[maxn], in_st[maxn * maxn], in_mst[maxn * maxn];
vector < int > st, mst;
mt19937 rng;
void initialize(int N)
{
n = N;
for (int i = 0; i < n; i ++)
for (int j = i + 1; j < n; j ++)
{
if (i != j)
{
if (i + 1 == j)
mst.push_back(i * n + j), in_mst[i * n + j] = 1;
else
st.push_back(i * n + j), in_st[i * n + j] = 1;
}
}
for (int i = 0; i < st.size(); i ++)
{
int idx = rng() % (int)(st.size());
swap(st[i], st[idx]);
}
}
vector < int > adj[maxn];
void dfs(int v, int cnt)
{
used[v] = cnt;
for (int u : adj[v])
{
if (!used[u])
dfs(u, cnt);
}
}
int hasEdge(int u, int v)
{
//cout << "----------------" << endl;
if (u > v)
swap(u, v);
int hs = u * n + v;
if (!in_mst[hs])
{
in_st[hs] = 0;
return 0;
}
for (int i = 0; i < n; i ++)
adj[i].clear(), used[i] = 0;
vector < int > new_st;
for (int cur: st)
{
if (in_st[cur])
new_st.push_back(cur);
}
st = new_st;
for (int edge : mst)
{
if (edge == hs)
continue;
///cout << edge / n << " " << edge % n << endl;
adj[edge / n].push_back(edge % n);
adj[edge % n].push_back(edge / n);
}
dfs(0, 1);
for (int i = 0; i < n; i ++)
if (used[i] == 0)
{
dfs(i, 2);
break;
}
for (int edge : st)
{
if (edge == hs)
continue;
if (used[edge / n] != used[edge % n])
{
///cout << "replace " << edge / n << " " << edge % n << endl;
in_st[hs] = 0;
in_mst[edge] = 1;
mst.push_back(edge);
in_mst[hs] = 0;
int pt = 0;
while(mst[pt] != hs)
pt ++;
mst.erase(mst.begin() + pt);
in_st[edge] = 0;
/**st.erase(hs);
mst.insert(edge);
st.erase(edge);
mst.erase(hs);*/
return 0;
}
}
return 1;
}
Compilation message (stderr)
game.cpp: In function 'void initialize(int)':
game.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = 0; i < st.size(); i ++)
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |