Submission #66564409
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, pair<int, int>>;
struct DSU {
vector<int> parent, rank;
DSU(int n) {
parent.resize(n);
rank.resize(n, 0);
iota(parent.begin(), parent.end(), 0);
}
int find(int x) {
if (parent[x] == x) return x;
return parent[x] = find(parent[x]);
}
bool same(int x, int y) {
return find(x) == find(y);
}
void merge(int x, int y) {
x = find(x); y = find(y);
if (x == y) return;
if (rank[x] < rank[y]) swap(x, y);
parent[y] = x;
if (rank[x] == rank[y]) rank[x]++;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
vector<pair<int, int>> g;
priority_queue<P, vector<P>, greater<P>> h;
DSU dsu(N + Q);
for (int i = 0; i < N; ++i) {
int a, b;
cin >> a >> b;
for (int j = 0; j < g.size(); ++j) {
int s = g[j].first, t = g[j].second;
h.push({abs(a - s) + abs(b - t), {j + 1, i + 1}});
}
g.emplace_back(a, b);
}
for (int i = 0; i < Q; ++i) {
int q;
cin >> q;
if (q == 1) {
int a, b;
cin >> a >> b;
N++;
for (int j = 0; j < g.size(); ++j) {
int s = g[j].first, t = g[j].second;
h.push({abs(a - s) + abs(b - t), {j + 1, N}});
}
g.emplace_back(a, b);
} else if (q == 2) {
ll pre;
int a, b;
bool found = false;
while (!h.empty()) {
auto top = h.top(); h.pop();
pre = top.first;
a = top.second.first;
b = top.second.second;
if (!dsu.same(a - 1, b - 1)) {
cout << pre << "\n";
dsu.merge(a - 1, b - 1);
// Merge all same-weighted edges with same weight
while (!h.empty() && h.top().first == pre) {
auto [_, nodes] = h.top(); h.pop();
dsu.merge(nodes.first - 1, nodes.second - 1);
}
found = true;
break;
}
}
if (!found) {
cout << -1 << "\n";
}
} else {
int a, b;
cin >> a >> b;
cout << (dsu.same(a - 1, b - 1) ? "Yes" : "No") << "\n";
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Connecting Points |
User |
potat_p |
Language |
C++ 20 (gcc 12.2) |
Score |
500 |
Code Size |
2655 Byte |
Status |
AC |
Exec Time |
487 ms |
Memory |
134336 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:44:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<int, int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
44 | for (int j = 0; j < g.size(); ++j) {
| ~~^~~~~~~~~~
Main.cpp:58:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<int, int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
58 | for (int j = 0; j < g.size(); ++j) {
| ~~^~~~~~~~~~
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_00.txt |
All |
00_sample_00.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_00.txt |
AC |
1 ms |
3384 KiB |
01_test_00.txt |
AC |
34 ms |
36116 KiB |
01_test_01.txt |
AC |
234 ms |
36192 KiB |
01_test_02.txt |
AC |
159 ms |
134328 KiB |
01_test_03.txt |
AC |
232 ms |
36012 KiB |
01_test_04.txt |
AC |
84 ms |
68904 KiB |
01_test_05.txt |
AC |
487 ms |
36136 KiB |
01_test_06.txt |
AC |
432 ms |
36080 KiB |
01_test_07.txt |
AC |
240 ms |
36192 KiB |
01_test_08.txt |
AC |
61 ms |
36120 KiB |
01_test_09.txt |
AC |
386 ms |
36060 KiB |
01_test_10.txt |
AC |
304 ms |
36104 KiB |
01_test_11.txt |
AC |
85 ms |
68948 KiB |
01_test_12.txt |
AC |
34 ms |
36020 KiB |
01_test_13.txt |
AC |
208 ms |
36048 KiB |
01_test_14.txt |
AC |
158 ms |
134336 KiB |
01_test_15.txt |
AC |
34 ms |
36052 KiB |
01_test_16.txt |
AC |
81 ms |
68992 KiB |
01_test_17.txt |
AC |
83 ms |
68872 KiB |
01_test_18.txt |
AC |
56 ms |
36088 KiB |
01_test_19.txt |
AC |
34 ms |
36108 KiB |
01_test_20.txt |
AC |
56 ms |
36120 KiB |
01_test_21.txt |
AC |
48 ms |
36108 KiB |
01_test_22.txt |
AC |
52 ms |
36184 KiB |
01_test_23.txt |
AC |
83 ms |
68896 KiB |
01_test_24.txt |
AC |
270 ms |
36144 KiB |
01_test_25.txt |
AC |
346 ms |
36152 KiB |
01_test_26.txt |
AC |
345 ms |
36192 KiB |
01_test_27.txt |
AC |
352 ms |
36056 KiB |
01_test_28.txt |
AC |
343 ms |
36072 KiB |
01_test_29.txt |
AC |
343 ms |
36112 KiB |
01_test_30.txt |
AC |
339 ms |
36136 KiB |
01_test_31.txt |
AC |
57 ms |
36172 KiB |
01_test_32.txt |
AC |
342 ms |
36056 KiB |
01_test_33.txt |
AC |
342 ms |
36096 KiB |
01_test_34.txt |
AC |
59 ms |
36020 KiB |
01_test_35.txt |
AC |
59 ms |
36136 KiB |
01_test_36.txt |
AC |
365 ms |
36052 KiB |
01_test_37.txt |
AC |
59 ms |
36052 KiB |
01_test_38.txt |
AC |
58 ms |
36108 KiB |
01_test_39.txt |
AC |
56 ms |
36116 KiB |
01_test_40.txt |
AC |
83 ms |
68832 KiB |
01_test_41.txt |
AC |
58 ms |
36048 KiB |
01_test_42.txt |
AC |
101 ms |
68912 KiB |
01_test_43.txt |
AC |
1 ms |
3512 KiB |