이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
using namespace std::placeholders;
#define llong long long
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()
// #define rand __rand
// mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // or mt19937_64
// template<class T = int> T rand(T range = numeric_limits<T>::max()) {
// return (T)(rng() % range);
// }
int query(vector<int> a, vector<int> b) {
return query(len(a), len(b), &a[0], &b[0]);
}
class Dsu {
private:
int n;
vector<int> set_head;
public:
Dsu(int n_) : n(n_), set_head(n) {
for (int i = n; i--; ) {
set_head[i] = i;
}
}
int find_set(int u) { return u == set_head[u] ? u : set_head[u] = find_set(set_head[u]); }
bool same_set(int u, int v) {
return find_set(u) == find_set(v);
}
void join(int u, int v) {
if (rand() & 1) swap(u, v);
set_head[find_set(u)] = find_set(v);
}
};
struct solution_batch_1 {
Dsu dsu;
solution_batch_1(int n): dsu(n) {
rep(edge_id, n - 1) {
bool has_ans = false;
rep(i, n) {
for (int f = i + 1; f < n and !has_ans; ++f) {
if (dsu.same_set(i, f)) continue;
if (!query({i + 1}, {f + 1})) continue;
has_ans = 1;
setRoad(i + 1, f + 1);
dsu.join(i, f);
}
if (has_ans) break;
}
}
}
};
void run(int n) {
solution_batch_1 temp(n);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |