#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1e6;
vector<pii> g[N];
vector<int> s[N], h;
int n;
void bfs(int u) {
queue<int> q;
vector<int> d(n, -1);
d[u] = 0;
q.push(u);
while (sz(q)) {
int x = q.front();
s[d[x]].push_back(x);
q.pop();
for (auto [to, id]: g[x]) {
if (d[to] == -1) {
d[to] = d[x] + 1;
q.push(to);
}
}
}
}
void find_pair(int n1, vector<int> u, vector<int> v, int a, int b) {
n = n1;
for (int i = 0; i < sz(u); i++) {
g[u[i]].push_back({v[i], i});
g[v[i]].push_back({u[i], i});
}
vector<int> w(sz(u));
ll dt = ask(w);
int l = 0, r = sz(u) - 1;
/*while (l <= r) {
int m = (l + r) / 2;
for (int i = 0; i <= m; i++) w[i] = 1;
if (ask(w) == dt) l = m + 1;
else r = m - 1;
for (int i = 0; i <= m; i++) w[i] = 0;
}*/
int x = u[l], y = v[l];
bfs(y);
l = 0, r = n;
while (l <= r) {
int m = (l + r) / 2;
for (int i = m; i <= n; i++) {
for (int vt: s[i]) {
for (auto [to, id]: g[vt]) {
w[id] = 1;
}
}
}
if (ask(w) == dt) r = m - 1;
else l = m + 1;
for (int i = m; i <= n; i++) {
for (int vt: s[i]) {
for (auto [to, id]: g[vt]) {
w[id] = 0;
}
}
}
}
int z = r;
l = 0, r = sz(s[z]) - 1;
while (l <= r) {
int m = (l + r) / 2;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[s[z][i]]) {
w[id] = 1;
}
}
if (ask(w) == dt) l = m + 1;
else r = m - 1;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[s[z][i]]) {
w[id] = 0;
}
}
}
x = s[z][l];
dt /= a;
for (int i = 0; i <= n; i++) s[i].clear();
bfs(x);
h = s[dt];
l = 0, r = sz(h) - 1;
while (l <= r) {
int m = (l + r) / 2;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[h[i]]) w[id] = 1;
}
if (ask(w) == dt * 1ll * a) l = m + 1;
else r = m - 1;
for (int i = 0; i <= m; i++) {
for (auto [to, id]: g[h[i]]) w[id] = 0;
}
}
answer(x, h[l]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
47188 KB |
Output is correct |
2 |
Correct |
15 ms |
47192 KB |
Output is correct |
3 |
Correct |
14 ms |
47304 KB |
Output is correct |
4 |
Correct |
14 ms |
47192 KB |
Output is correct |
5 |
Correct |
14 ms |
47192 KB |
Output is correct |
6 |
Correct |
14 ms |
47192 KB |
Output is correct |
7 |
Correct |
19 ms |
47192 KB |
Output is correct |
8 |
Correct |
14 ms |
47192 KB |
Output is correct |
9 |
Correct |
14 ms |
47188 KB |
Output is correct |
10 |
Correct |
14 ms |
47192 KB |
Output is correct |
11 |
Correct |
14 ms |
47192 KB |
Output is correct |
12 |
Correct |
14 ms |
47192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
47448 KB |
Output is correct |
2 |
Correct |
23 ms |
48064 KB |
Output is correct |
3 |
Correct |
125 ms |
53468 KB |
Output is correct |
4 |
Correct |
103 ms |
53444 KB |
Output is correct |
5 |
Correct |
110 ms |
53580 KB |
Output is correct |
6 |
Correct |
99 ms |
53600 KB |
Output is correct |
7 |
Correct |
114 ms |
53520 KB |
Output is correct |
8 |
Correct |
101 ms |
53288 KB |
Output is correct |
9 |
Correct |
92 ms |
53336 KB |
Output is correct |
10 |
Correct |
109 ms |
53472 KB |
Output is correct |
11 |
Correct |
122 ms |
53364 KB |
Output is correct |
12 |
Correct |
101 ms |
53520 KB |
Output is correct |
13 |
Correct |
100 ms |
53368 KB |
Output is correct |
14 |
Correct |
109 ms |
53580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
48208 KB |
Output is correct |
2 |
Correct |
29 ms |
49084 KB |
Output is correct |
3 |
Correct |
36 ms |
49752 KB |
Output is correct |
4 |
Correct |
86 ms |
55124 KB |
Output is correct |
5 |
Correct |
79 ms |
55016 KB |
Output is correct |
6 |
Correct |
77 ms |
55120 KB |
Output is correct |
7 |
Correct |
72 ms |
55188 KB |
Output is correct |
8 |
Correct |
80 ms |
55036 KB |
Output is correct |
9 |
Correct |
82 ms |
55040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
47448 KB |
Output is correct |
2 |
Correct |
22 ms |
47960 KB |
Output is correct |
3 |
Correct |
75 ms |
52084 KB |
Output is correct |
4 |
Correct |
103 ms |
53552 KB |
Output is correct |
5 |
Correct |
98 ms |
53456 KB |
Output is correct |
6 |
Correct |
97 ms |
53228 KB |
Output is correct |
7 |
Correct |
95 ms |
53444 KB |
Output is correct |
8 |
Correct |
107 ms |
53248 KB |
Output is correct |
9 |
Correct |
99 ms |
53688 KB |
Output is correct |
10 |
Correct |
107 ms |
53420 KB |
Output is correct |
11 |
Correct |
108 ms |
53132 KB |
Output is correct |
12 |
Correct |
103 ms |
53380 KB |
Output is correct |
13 |
Correct |
100 ms |
53196 KB |
Output is correct |
14 |
Correct |
107 ms |
53516 KB |
Output is correct |
15 |
Correct |
96 ms |
53356 KB |
Output is correct |
16 |
Correct |
91 ms |
53660 KB |
Output is correct |
17 |
Correct |
104 ms |
53072 KB |
Output is correct |
18 |
Correct |
113 ms |
53548 KB |
Output is correct |
19 |
Correct |
108 ms |
53516 KB |
Output is correct |
20 |
Correct |
98 ms |
53556 KB |
Output is correct |
21 |
Correct |
87 ms |
54896 KB |
Output is correct |
22 |
Correct |
105 ms |
54284 KB |
Output is correct |
23 |
Correct |
104 ms |
53960 KB |
Output is correct |
24 |
Correct |
107 ms |
54080 KB |
Output is correct |
25 |
Correct |
104 ms |
55064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47960 KB |
Output is correct |
2 |
Incorrect |
25 ms |
48152 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47960 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |