이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1500;
int n, x, y, curr, need, cnt, p[N], sz[N];
unordered_set<int> vis, adj[N];
int findSet(int x) {
return (p[x] == x ? x : p[x] = findSet(p[x]));
}
void unite(int x, int y) {
x = findSet(x);
y = findSet(y);
if (sz[x] < sz[y]) swap(x, y);
p[y] = x;
sz[x] += sz[y];
while (!adj[y].empty()) {
int z = *adj[y].begin();
adj[z].insert(x);
adj[x].insert(z);
adj[z].erase(y);
adj[y].erase(adj[y].begin());
}
}
void addEdge(int x, int y) {
adj[x].insert(y);
adj[y].insert(x);
unite(x, y);
}
void removeEdge(int x, int y) {
adj[x].erase(y);
adj[y].erase(x);
}
void dfs(int x) {
vis.insert(x);
cnt += sz[x];
if (cnt >= need) return;
for (int y : adj[x]) {
if (vis.find(y) != vis.end()) continue;
dfs(y);
}
}
void initialize(int NN) {
n = NN;
curr = 0;
need = 1;
for (int i = 0; i < n; i++) {
p[i] = i;
sz[i] = 1;
for (int j = i+1; j < n; j++) {
adj[i].insert(j);
adj[j].insert(i);
}
}
}
int hasEdge(int u, int v) {
curr++;
if (curr >= (n-need)*need) need++;
u = findSet(u);
v = findSet(v);
if (u == v) return 0;
removeEdge(u, v);
vis.clear();
cnt = 0;
dfs(u);
if (cnt < need) {
addEdge(u, v);
return 1;
}
vis.clear();
cnt = 0;
dfs(v);
if (cnt < need) {
addEdge(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... |