# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
1133410 | | qrn | ICC (CEOI16_icc) | C++20 | | 79 ms | 632 KiB |
// ivan carvalhoya minnetdarligimi bildirirem
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
mt19937 rng(time(0));
// vector<pair<int,int>>roads;
// int ind = 0;
// int query(int a, int b, int a1[], int b1[]) {
// for(int i = 0; i < a; i++) {
// for(int j = 0; j < b; j++) {
// if(roads[ind].first == a1[i] && roads[ind].second == b1[j] || (roads[ind].first == b1[j] && roads[ind].second == a1[i])) {
// return 1;
// }
// }
// }
// return 0;
// }
// void setRoad(int a, int b) {
// cout << "Setting the road was succesful. " << a << " " << b << endl;
// }
struct DSU {
vector<vector<int>> component;
vector<int> parent, sze;
DSU(int n) {
parent.assign(n + 1, 0ll);
sze.assign(n + 1, 0ll);
component.resize(n + 1);
for(int i = 1; i <= n; i++) {
sze[i] = 1;
parent[i] = i;
component[i].push_back(i);
}
}
int root(int x) {
if(x == parent[x]) return x;
return parent[x] = root(parent[x]);
}
void unite(int a, int b) {
a = root(a);
b = root(b);
if(a == b) return;
if(sze[a] > sze[b]) swap(a, b);
sze[a] += sze[b];
parent[b] = a;
for(auto u : component[b]) component[a].push_back(u);
component[b].clear();
}
};
void run(int N) {
DSU dsu(N + 1);
for(int turn = 0; turn < N - 1; turn++) {
vector<int> upA, downA, total, UpA;
for(int i = 1; i <= N; i++) {
if(dsu.root(i) == i) {
total.push_back(i);
}
}
shuffle(total.begin(), total.end(), rng);
for(int i = 0; i < 7; i++) {
upA.clear();
downA.clear();
for(int j = 0; j < total.size(); j++) {
if((1 << i) & j) {
for(auto u : dsu.component[total[j]]) downA.pb(u);
} else {
for(auto u : dsu.component[total[j]]) upA.pb(u);
}
}
if(query(upA.size(), downA.size(), upA.data(), downA.data())) {
break;
}
}
// cout << "Current turn: " << turn << endl;
// for(int i : upA) cout << i << " ";
// cout << endl;
// for(int i : downA) cout << i << " ";
// cout << endl;
int l = 0, r = upA.size() - 1;
while(l < r) {
int mid = (l + r) / 2;
vector<int> left, right;
for(int i = l; i <= mid; i++) left.push_back(upA[i]);
for(int i = mid + 1; i <= r; i++) right.push_back(upA[i]);
if(query(left.size(), downA.size(), left.data(), downA.data())) {
upA = left;
r = mid;
} else {
upA = right;
l = mid + 1;
}
}
l = 0, r = downA.size() - 1;
while(l < r) {
int mid = (l + r) / 2;
vector<int> left, right;
for(int i = l; i <= mid; i++) left.push_back(downA[i]);
for(int i = mid + 1; i <= r; i++) right.push_back(downA[i]);
if(query(upA.size(), left.size(), upA.data(), left.data())) {
downA = left;
r = mid;
} else {
downA = right;
l = mid + 1;
}
}
int ep1 = upA[0], ep2 = downA[0];
dsu.unite(ep1, ep2);
setRoad(ep1, ep2);
// ind++;
}
}
// int main() {
// int n=6;
// roads.pb({1,2});
// roads.pb({3,5});
// roads.pb({4,5});
// roads.pb({5,6});
// roads.pb({3,4});
// run(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... |