이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "icc.h"
using namespace std;
#ifndef d
#define d(...)
#endif
#define st first
#define nd second
#define pb push_back
#define siz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
typedef long long LL;
typedef long double LD;
constexpr int INF=1e9+7;
constexpr LL INFL=1e18;
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.st << "," << P.nd << ")";
}
constexpr int maxn = 105;
using Component = vector<int>;
int n;
vector<Component> C;
vector<int> get_vertices(vector<int>& ind) {
vector<int> ret;
for(auto i:ind)
for(auto x:C[i])
ret.push_back(x);
return ret;
}
int make_query(vector<int> l, vector<int> r) {
return query(l.size(), r.size(), l.data(), r.data());
}
void merge(int a, int b) {
auto f = [&](int x) {
for(size_t i=0; i<C.size(); i++)
if(find(all(C[i]), x) != C[i].end())
return i;
return C.size();
};
a = f(a), b = f(b);
for(auto x:C[b])
C[a].push_back(x);
C[b] = C.back();
C.pop_back();
}
void run(int _n) {
n = _n;
for(int i=1; i<=n; i++) {
C.push_back({i});
}
// mt19937 rng(time(0));
for(int _=0; _<n-1; _++) {
vector<int> L, R, ind(C.size());
iota(all(ind), 0);
int half = ind.size() / 2;
while(true) {
shuffle(all(ind), mt19937(time(0)));
L.assign(ind.begin(), ind.begin() + half);
R.assign(ind.begin() + half, ind.end());
if(make_query(get_vertices(L), get_vertices(R))) break;
}
L = get_vertices(L);
R = get_vertices(R);
auto it = L.begin(), it2 = L.end();
while(it + 1 != it2) {
auto s = it + distance(it, it2) / 2;
if(make_query(vector<int>(it, s), R))
it2 = s;
else
it = s;
}
int a = *it;
it = R.begin(), it2 = R.end();
while(it + 1 != it2) {
auto s = it + distance(it, it2) / 2;
if(make_query(vector<int>(it, s), L))
it2 = s;
else
it = s;
}
int b = *it;
setRoad(a, b);
merge(a, b);
}
}
# | 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... |