이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <unordered_map>
#include <chrono>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include "game.h"
using namespace std;
const int maxN = 1500;
#define BUGO(x) cerr << #x << " = " << (x) << '\n';
#define BUGOARR(a) {cerr << #a << ": "; for (auto i: a) cerr << i << ' '; cerr << '\n';}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int n;
int cnt[maxN][maxN];
unordered_map<int, int, custom_hash> nei[maxN];
int par[maxN], sz[maxN], centre[maxN];
int Root(int v) {
return v == par[v] ? v : par[v] = Root(par[v]);
}
void Union(int u, int v)
{
u = Root(u); v = Root(v);
if (u == v) return;
if (sz[u] > sz[v]) swap(u, v);
int c1 = centre[u], c2 = centre[v];
if (nei[c1].size() > nei[c2].size()) swap(c1, c2);
for (pair<int, int> to: nei[c1])
{
int t = to.first;
if (t == c2) continue;
nei[t].erase(c1);
nei[c2][t] += to.second;
nei[t][c2] += to.second;
}
// nei[c1].clear();
sz[v] += sz[u];
par[u] = v;
centre[v] = c2;
}
void initialize(int n_) {
n = n_;
for (int v = 0; v < n; ++v) {
par[v] = v, sz[v] = 1, centre[v] = v;
nei[v].reserve(n);
nei[v].reserve(1024);
nei[v].max_load_factor(0.25);
}
}
int hasEdge(int u, int v) {
int c1 = centre[Root(u)];
int c2 = centre[Root(v)];
int tch = ++nei[c1][c2];
++nei[c2][c1];
if (tch == sz[Root(u)] * sz[Root(v)])
{
Union(u, v);
return 1;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |