#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
vector<vector<int>> adj(n);
int m = u.size();
for (int i = 0; i < m; ++i)
adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);
vector<int> in(n);
vector<int> dfs_ord;
int s = -1;
int t = 0;
function<void(int, int)> dfs = [&](int node, int par) {
dfs_ord.push_back(node);
in[node] = t++;
for (auto v : adj[node]) {
if (v == par) continue;
if (v == s) continue;
dfs(v, node);
}
};
dfs(0, -1);
// subgraph w. only verts with in[i] < t
// t = tl -> len ineq.
// t = th -> len eq.
int tl = 0, th = t;
vector<int> hl(m, 0);
int64_t req_d = ask(hl);
while (tl + 1 < th) {
int tm = (tl + th) / 2;
for (int i = 0; i < m; ++i) {
hl[i] = in[u[i]] >= tm || in[v[i]] >= tm;
}
if (ask(hl) == req_d) {
th = tm;
} else {
tl = tm;
}
}
s = dfs_ord[tl];
dfs_ord.clear();
in.assign(n, -1);
t = 0;
dfs(s, -1);
hl.assign(m, 1);
tl = 0, th = t;
req_d = ask(hl);
while (tl + 1 < th) {
int tm = (tl + th) / 2;
for (int i = 0; i < m; ++i) {
hl[i] = in[u[i]] < tm && in[v[i]] < tm;
}
if (ask(hl) == req_d) {
th = tm;
} else {
tl = tm;
}
}
t = dfs_ord[tl];
answer(s, t);
}
#ifndef EVAL
#include "grader.cpp"
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
1112 KB |
Output is correct |
3 |
Correct |
91 ms |
8060 KB |
Output is correct |
4 |
Correct |
106 ms |
8296 KB |
Output is correct |
5 |
Correct |
92 ms |
8108 KB |
Output is correct |
6 |
Correct |
107 ms |
8052 KB |
Output is correct |
7 |
Correct |
97 ms |
8056 KB |
Output is correct |
8 |
Correct |
90 ms |
8044 KB |
Output is correct |
9 |
Correct |
111 ms |
8048 KB |
Output is correct |
10 |
Correct |
95 ms |
8512 KB |
Output is correct |
11 |
Correct |
110 ms |
9668 KB |
Output is correct |
12 |
Correct |
104 ms |
10644 KB |
Output is correct |
13 |
Correct |
110 ms |
9824 KB |
Output is correct |
14 |
Correct |
99 ms |
9952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1880 KB |
Output is correct |
2 |
Correct |
16 ms |
3672 KB |
Output is correct |
3 |
Correct |
24 ms |
5268 KB |
Output is correct |
4 |
Correct |
72 ms |
14996 KB |
Output is correct |
5 |
Correct |
69 ms |
15008 KB |
Output is correct |
6 |
Correct |
74 ms |
14992 KB |
Output is correct |
7 |
Correct |
76 ms |
15004 KB |
Output is correct |
8 |
Correct |
68 ms |
14996 KB |
Output is correct |
9 |
Correct |
76 ms |
14992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
1276 KB |
Output is correct |
3 |
Correct |
73 ms |
6408 KB |
Output is correct |
4 |
Correct |
103 ms |
8060 KB |
Output is correct |
5 |
Correct |
91 ms |
8048 KB |
Output is correct |
6 |
Correct |
92 ms |
8312 KB |
Output is correct |
7 |
Correct |
89 ms |
8056 KB |
Output is correct |
8 |
Correct |
92 ms |
8236 KB |
Output is correct |
9 |
Correct |
110 ms |
8052 KB |
Output is correct |
10 |
Correct |
113 ms |
8064 KB |
Output is correct |
11 |
Correct |
107 ms |
9236 KB |
Output is correct |
12 |
Correct |
106 ms |
10508 KB |
Output is correct |
13 |
Correct |
113 ms |
9984 KB |
Output is correct |
14 |
Correct |
109 ms |
10448 KB |
Output is correct |
15 |
Correct |
80 ms |
8068 KB |
Output is correct |
16 |
Correct |
96 ms |
8076 KB |
Output is correct |
17 |
Correct |
101 ms |
10108 KB |
Output is correct |
18 |
Correct |
101 ms |
10232 KB |
Output is correct |
19 |
Correct |
97 ms |
8052 KB |
Output is correct |
20 |
Correct |
113 ms |
11028 KB |
Output is correct |
21 |
Correct |
80 ms |
8316 KB |
Output is correct |
22 |
Correct |
73 ms |
8324 KB |
Output is correct |
23 |
Correct |
81 ms |
8504 KB |
Output is correct |
24 |
Correct |
98 ms |
9056 KB |
Output is correct |
25 |
Correct |
100 ms |
14264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
257 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
215 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |