이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
#define lb lower_bound
#define pb push_back
#define LINE "------------\n"
#define ALL(x) x.begin(),x.end()
using namespace std;
using PII = pair <int, int>;
const int N = 1500;
vector <int> paths[N];
int n;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int pos[N][N];
void initialize(int _n) {
n = _n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (i == j) continue;
paths[i].pb(j);
}
for (int i = 0; i < n; i++)
shuffle(ALL(paths[i]), rng);
for (int i = 0; i < n; i++)
for (int j = 0; j < n-1; j++)
pos[i][paths[i][j]] = j;
// for (int i = 0; i < n; i++) {
// cout << i << ": ";
// for (auto el : paths[i]) cout << el << ' '; cout << '\n';
// }
}
int par[N];
int find(int a) {
return par[a] = (par[a] == a ? a : find(par[a]));
}
bool merge(int a, int b) {
a = find(a);
b = find(b);
if (a == b) return 0;
par[b] = a;
return 1;
}
vector <PII> must;
int hasEdge(int u, int v) {
// cout << LINE;
if (paths[u].size() == 1 || paths[v].size() == 1) {
must.pb({u, v});
{
int x = paths[u].size();
int y = pos[u][v];
if (x != y) {
swap(paths[u][y], paths[u][x-1]);
pos[u][y] = y;
}
paths[u].pop_back();
}
{
int x = paths[v].size();
int y = pos[v][u];
if (x != y) {
swap(paths[v][y], paths[v][x-1]);
pos[v][y] = y;
}
paths[v].pop_back();
}
return 1;
}
int disjoint = n;
iota(par, par+n, 0);
{
int x = paths[u].size();
int y = pos[u][v];
if (x != y) {
swap(paths[u][y], paths[u][x-1]);
pos[u][y] = y;
}
paths[u].pop_back();
}
{
int x = paths[v].size();
int y = pos[v][u];
if (x != y) {
swap(paths[v][y], paths[v][x-1]);
pos[v][y] = y;
}
paths[v].pop_back();
}
for (auto [a, b] : must) {
// cout << "must: " << a << ' ' << b << '\n';
disjoint -= merge(a, b);
}
// cout << u << ' ' << v << '\n';
// for (int i = 0; i < n; i++) {
// cout << i << ": ";
// for (auto el : paths[i]) cout << el << ' '; cout << '\n';
// }
for (int i = 0; i < n; i++) {
if (paths[i].size() > 20)
for (int j = 0; j < 20 && disjoint > 1; j++) {
int x = paths[i][rng() % paths[i].size()];
disjoint -= merge(i, x);
}
else
for (int j = 0; j < paths[i].size() && disjoint > 1; j++) {
int x = merge(i, paths[i][j]);
// cout << "CHECK: " << i << " " << paths[i][j] << ' ' << x << '\n';
disjoint -= x;
}
}
// cout << disjoint << '\n';
// cout << '\n';
if (disjoint == 1) return 0;
must.pb({u, v});
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:104:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for (int j = 0; j < paths[i].size() && disjoint > 1; 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... |