#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
using ll = long long;
const int N = 90090;
vector<pair<int, int>> adj[N], e;
int n;
int p[N], sz[N];
int fr(int i) {
return (p[i] == i) ? i : p[i] = fr(p[i]);
}
void dfs(int v, int p = -1) {
for (auto& x : adj[v]) {
if (x.first == p) continue;
e.push_back({ x.second, x.first });
dfs(x.first, v);
}
}
void find_pair(int NN, vector<int> U, vector<int> V, int A, int B) {
n = NN;
int m = U.size();
for (int i = 0;i < n;i++) p[i] = i;
for (int i = 0;i < m;i++) {
int u = U[i], v = V[i];
int pu = fr(u), pv = fr(v);
if (pu != pv) {
adj[u].push_back({ v,i });
adj[v].push_back({ u,i });
p[pu] = pv;
}
}
vector<int> QQ(m, 0);
ll mnp = ask(QQ);
dfs(0);
int l = 1, r = n - 1;
while (l < r) {
int mid = (l + r) / 2;
vector<int> q(m, 1);
for (int i = 0;i < mid;i++) {
q[e[i].first] = 0;
}
if (ask(q) == mnp) r = mid;
else l = mid + 1;
}
int city2 = e[l - 1].second;
e.clear();
dfs(city2);
l = 1, r = n - 1;
while (l < r) {
int mid = (l + r) / 2;
vector<int> q(m, 1);
for (int i = 0;i < mid;i++) {
q[e[i].first] = 0;
}
if (ask(q) == mnp) r = mid;
else l = mid + 1;
}
int city1 = e[l - 1].second;
answer(city1, city2);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3088 KB |
Output is correct |
2 |
Correct |
1 ms |
3084 KB |
Output is correct |
3 |
Correct |
1 ms |
3088 KB |
Output is correct |
4 |
Correct |
1 ms |
3092 KB |
Output is correct |
5 |
Correct |
1 ms |
3092 KB |
Output is correct |
6 |
Correct |
1 ms |
3092 KB |
Output is correct |
7 |
Correct |
1 ms |
3096 KB |
Output is correct |
8 |
Correct |
1 ms |
3096 KB |
Output is correct |
9 |
Correct |
1 ms |
3344 KB |
Output is correct |
10 |
Correct |
1 ms |
3084 KB |
Output is correct |
11 |
Correct |
1 ms |
3088 KB |
Output is correct |
12 |
Correct |
1 ms |
3088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3148 KB |
Output is correct |
2 |
Correct |
9 ms |
3788 KB |
Output is correct |
3 |
Correct |
82 ms |
9512 KB |
Output is correct |
4 |
Correct |
92 ms |
9504 KB |
Output is correct |
5 |
Correct |
82 ms |
9512 KB |
Output is correct |
6 |
Correct |
91 ms |
9744 KB |
Output is correct |
7 |
Correct |
91 ms |
9372 KB |
Output is correct |
8 |
Correct |
78 ms |
9512 KB |
Output is correct |
9 |
Correct |
85 ms |
9736 KB |
Output is correct |
10 |
Correct |
80 ms |
9352 KB |
Output is correct |
11 |
Correct |
92 ms |
10316 KB |
Output is correct |
12 |
Correct |
88 ms |
11108 KB |
Output is correct |
13 |
Correct |
90 ms |
10688 KB |
Output is correct |
14 |
Correct |
90 ms |
10316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4428 KB |
Output is correct |
2 |
Correct |
16 ms |
6008 KB |
Output is correct |
3 |
Correct |
23 ms |
6864 KB |
Output is correct |
4 |
Correct |
70 ms |
14576 KB |
Output is correct |
5 |
Correct |
65 ms |
14580 KB |
Output is correct |
6 |
Correct |
72 ms |
14364 KB |
Output is correct |
7 |
Correct |
61 ms |
14580 KB |
Output is correct |
8 |
Correct |
67 ms |
14376 KB |
Output is correct |
9 |
Correct |
56 ms |
14352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3144 KB |
Output is correct |
2 |
Correct |
9 ms |
3656 KB |
Output is correct |
3 |
Correct |
65 ms |
8236 KB |
Output is correct |
4 |
Correct |
81 ms |
9480 KB |
Output is correct |
5 |
Correct |
85 ms |
9508 KB |
Output is correct |
6 |
Correct |
84 ms |
9564 KB |
Output is correct |
7 |
Correct |
93 ms |
9744 KB |
Output is correct |
8 |
Correct |
79 ms |
9516 KB |
Output is correct |
9 |
Correct |
87 ms |
9736 KB |
Output is correct |
10 |
Correct |
86 ms |
9360 KB |
Output is correct |
11 |
Correct |
86 ms |
10028 KB |
Output is correct |
12 |
Correct |
94 ms |
11060 KB |
Output is correct |
13 |
Correct |
96 ms |
10828 KB |
Output is correct |
14 |
Correct |
97 ms |
10712 KB |
Output is correct |
15 |
Correct |
71 ms |
9372 KB |
Output is correct |
16 |
Correct |
71 ms |
9356 KB |
Output is correct |
17 |
Correct |
92 ms |
10644 KB |
Output is correct |
18 |
Correct |
84 ms |
10540 KB |
Output is correct |
19 |
Correct |
77 ms |
9364 KB |
Output is correct |
20 |
Correct |
92 ms |
11424 KB |
Output is correct |
21 |
Correct |
70 ms |
10300 KB |
Output is correct |
22 |
Correct |
57 ms |
9900 KB |
Output is correct |
23 |
Correct |
70 ms |
9620 KB |
Output is correct |
24 |
Correct |
77 ms |
10220 KB |
Output is correct |
25 |
Correct |
86 ms |
14044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
3672 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
3924 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |