#include "highway.h"
// #include "grader.cpp"
#include <vector>
#include <map>
#include <utility>
#include <iostream>
#include <queue>
#define ll long long
using namespace std;
const int maxn = (int)2e5 + 7;
vector < int > gr[maxn];
vector < int > nwgr[maxn];
vector < int > vec[maxn];
vector < int > w;
vector < int > del;
map < pair < int, int >, int > mp;
int id[maxn], h[maxn], p[maxn], idc[maxn];
int get(int a) {
if (id[a] == a) return a;
return id[a] = get(id[a]);
}
void connect(int a, int b) {
a = get(a);
b = get(b);
id[a] = b;
}
void addedge(int a, int b) {
nwgr[a].push_back(b);
nwgr[b].push_back(a);
}
void dfs(int v, int pr) {
vec[h[v]].push_back(v);
p[v] = pr;
idc[v] = mp[{v, pr}];
for (int to : nwgr[v]) {
if (to == pr) continue;
h[to] = h[v] + 1;
del.push_back(mp[{v, to}]);
w[del.back()] = 1;
dfs(to, v);
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int n = N;
int m = U.size();
ll dist = 0;
w.resize(m, 0);
dist = ask(w) / A;
for (int i = 0; i < n; i++) {
id[i] = i;
}
for (int i = 0; i < m; i++) {
int u, v;
u = U[i];
v = V[i];
mp[{v, u}] = mp[{u, v}] = i;
gr[u].push_back(v);
gr[v].push_back(u);
}
int l = -1;
int r = m - 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
for (int i = 0; i <= mid; i++) {
w[i] = 1;
}
ll T = ask(w);
for (int i = 0; i <= mid; i++) {
w[i] = 0;
}
if (T == dist * A) {
l = mid;
} else {
r = mid;
}
}
for (int i = 0; i < m; i++) {
w[i] = 1;
}
w[r] = 0;
int u, v;
u = U[r];
v = V[r];
queue < int > q;
q.push(u);
q.push(v);
addedge(u, v);
connect(u, v);
while (!q.empty()) {
int asd = q.front();
q.pop();
for (int to : gr[asd]) {
if (get(to) != get(asd)) {
addedge(asd, to);
connect(asd, to);
w[mp[{asd, to}]] = 0;
q.push(to);
}
}
}
dfs(u, v);
int asd = (ask(w) - dist * A) / (B - A);
for (int to : del) {
w[to] = 0;
}
del.clear();
l = -1;
r = vec[asd].size() - 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 1;
}
ll T = ask(w);
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 0;
}
if (T == dist * A) {
l = mid;
} else {
r = mid;
}
}
int s, t;
s = vec[asd][r];
for (int i = 0; i < n; i++) {
vec[i].clear();
}
h[s] = 0;
dfs(s, s);
for (int to : del) {
w[to] = 0;
}
asd = dist;
l = -1;
r = vec[asd].size() - 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 1;
}
ll T = ask(w);
for (int i = 0; i <= mid; i++) {
int v = vec[asd][i];
w[idc[v]] = 0;
}
if (T == dist * A) {
l = mid;
} else {
r = mid;
}
}
t = vec[asd][r];
answer(s, t);
}
/*
7 7 4 5 2 5
0 2
0 5
1 2
2 3
3 4
4 5
4 6
4 4 3 4 2 3
0 1
1 2
2 3
3 0
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14328 KB |
Output is correct |
3 |
Correct |
15 ms |
14500 KB |
Output is correct |
4 |
Correct |
15 ms |
14500 KB |
Output is correct |
5 |
Correct |
15 ms |
14328 KB |
Output is correct |
6 |
Correct |
15 ms |
14456 KB |
Output is correct |
7 |
Correct |
14 ms |
14408 KB |
Output is correct |
8 |
Correct |
15 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14328 KB |
Output is correct |
10 |
Correct |
14 ms |
14416 KB |
Output is correct |
11 |
Correct |
15 ms |
14376 KB |
Output is correct |
12 |
Correct |
15 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
14584 KB |
Output is correct |
2 |
Correct |
59 ms |
16764 KB |
Output is correct |
3 |
Correct |
683 ms |
36048 KB |
Output is correct |
4 |
Correct |
591 ms |
35680 KB |
Output is correct |
5 |
Correct |
590 ms |
35608 KB |
Output is correct |
6 |
Correct |
570 ms |
35712 KB |
Output is correct |
7 |
Correct |
586 ms |
35636 KB |
Output is correct |
8 |
Correct |
575 ms |
35620 KB |
Output is correct |
9 |
Correct |
689 ms |
36052 KB |
Output is correct |
10 |
Correct |
589 ms |
35640 KB |
Output is correct |
11 |
Correct |
646 ms |
37376 KB |
Output is correct |
12 |
Correct |
685 ms |
39036 KB |
Output is correct |
13 |
Correct |
594 ms |
38180 KB |
Output is correct |
14 |
Correct |
671 ms |
38232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
17676 KB |
Output is correct |
2 |
Correct |
74 ms |
20984 KB |
Output is correct |
3 |
Correct |
106 ms |
24512 KB |
Output is correct |
4 |
Correct |
285 ms |
41908 KB |
Output is correct |
5 |
Correct |
319 ms |
42172 KB |
Output is correct |
6 |
Correct |
324 ms |
43808 KB |
Output is correct |
7 |
Correct |
340 ms |
45476 KB |
Output is correct |
8 |
Correct |
324 ms |
42920 KB |
Output is correct |
9 |
Correct |
337 ms |
43184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
14632 KB |
Output is correct |
2 |
Correct |
57 ms |
16760 KB |
Output is correct |
3 |
Correct |
413 ms |
31124 KB |
Output is correct |
4 |
Correct |
580 ms |
35596 KB |
Output is correct |
5 |
Correct |
664 ms |
35620 KB |
Output is correct |
6 |
Correct |
587 ms |
35696 KB |
Output is correct |
7 |
Correct |
676 ms |
35732 KB |
Output is correct |
8 |
Correct |
671 ms |
35732 KB |
Output is correct |
9 |
Correct |
680 ms |
35940 KB |
Output is correct |
10 |
Correct |
680 ms |
35924 KB |
Output is correct |
11 |
Correct |
747 ms |
37504 KB |
Output is correct |
12 |
Correct |
579 ms |
39372 KB |
Output is correct |
13 |
Correct |
675 ms |
38352 KB |
Output is correct |
14 |
Correct |
664 ms |
38092 KB |
Output is correct |
15 |
Correct |
568 ms |
35704 KB |
Output is correct |
16 |
Correct |
583 ms |
35644 KB |
Output is correct |
17 |
Correct |
689 ms |
37860 KB |
Output is correct |
18 |
Correct |
708 ms |
38804 KB |
Output is correct |
19 |
Correct |
676 ms |
35640 KB |
Output is correct |
20 |
Correct |
652 ms |
39304 KB |
Output is correct |
21 |
Correct |
507 ms |
38192 KB |
Output is correct |
22 |
Correct |
659 ms |
38100 KB |
Output is correct |
23 |
Correct |
663 ms |
37260 KB |
Output is correct |
24 |
Correct |
636 ms |
37620 KB |
Output is correct |
25 |
Correct |
703 ms |
45152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
16964 KB |
Output is correct |
2 |
Correct |
67 ms |
17100 KB |
Output is correct |
3 |
Correct |
617 ms |
37208 KB |
Output is correct |
4 |
Incorrect |
896 ms |
38760 KB |
Output is incorrect: {s, t} is wrong. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
16920 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |