이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()
int n;
vii parent;
vector<set<int>> adj;
int queries;
void initialize(int N) {
queries = 0;
n = N;
parent.assign(n, -1);
adj.assign(n, {});
rep(i, n - 1) {
ffor(j, i + 1, n) {
adj[i].emplace(j);
adj[j].emplace(i);
}
}
}
int root(int x) {
if (parent[x] < 0) return x;
return parent[x] = root(parent[x]);
}
int hasEdge(int u, int v) {
if (root(u) == root(v)) {
return 1;
}
adj[u].erase(v);
vector<bool> vis(n);
int cnt = 1;
vis[u] = true;
deque<int> q = {u};
while (!q.empty()) {
int uu = q.front();
q.pop_front();
forin(vv, adj[uu]) {
if (!vis[vv]) {
vis[vv] = true;
cnt++;
q.emplace_back(vv);
}
}
}
if (cnt == n) {
adj[v].erase(u);
return 0;
} else {
adj[u].emplace(v);
int ru = root(u), rv = root(v);
if (parent[ru] < parent[rv]) {
swap(ru, rv);
}
parent[rv] += parent[ru];
parent[ru] = rv;
return 1;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |