#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll linf = ll(1e18);
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;
#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())
#define all(x) begin(x),end(x)
#if _LOCAL
#define assert(x) if (!(x)) __debugbreak()
#endif
typedef long long ll;
void dfs(int u, int p, int v, int d, int sign, vector<vector<p2>>&edges, vi& edgedist, vi& nodedist)
{
nodedist[u] = d;
repe(e, edges[u])
{
if (e.first == p) continue;
edgedist[e.second] = d*sign * (e.first == v ? -1 : 1);
dfs(e.first, u, v, d + 1, sign * (e.first==v?-1:1), edges, edgedist, nodedist);
}
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B)
{
int m = sz(U);
ll baseline = ask(vi(m, 0));
int lo = -1;
int hi = m;
while (lo+1<hi)
{
int mid = (lo + hi) / 2;
vi w(m);
rep(i, mid + 1) w[i] = 1;
if (ask(w) > baseline)
{
hi = mid;
}
else lo = mid;
}
int u = U[hi];
int v = V[hi];
vector<vector<p2>> edges(n);
rep(i, m)
{
int a = U[i];
int b = V[i];
edges[a].emplace_back(b, i);
edges[b].emplace_back(a, i);
}
vi ans;
bool disable_e = 0;
rep(_, 2)
{
vi edgedist(m);
vi nodedist(n);
dfs(u, u, v, 10, -1, edges, edgedist, nodedist);
vector<p2> edge_order;
rep(i, m) edge_order.emplace_back(edgedist[i], i);
sort(edge_order.rbegin(), edge_order.rend());
lo = -1;
hi = m;
while (lo+1<hi)
{
int mid = (lo + hi) / 2;
vi w(m);
rep(i, mid + 1) w[edge_order[i].second] = 1;
if (ask(w) > baseline)
{
hi = mid;
}
else lo = mid;
}
int e = edge_order[hi].second;
ans.push_back(nodedist[U[e]]>nodedist[V[e]]?U[e]:V[e]);
swap(u, v);
}
answer(ans[0], ans[1]);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:68:7: warning: unused variable 'disable_e' [-Wunused-variable]
68 | bool disable_e = 0;
| ^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
372 KB |
Output is correct |
4 |
Correct |
1 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 |
1 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 |
11 ms |
1496 KB |
Output is correct |
3 |
Correct |
106 ms |
9756 KB |
Output is correct |
4 |
Correct |
100 ms |
9980 KB |
Output is correct |
5 |
Correct |
111 ms |
9760 KB |
Output is correct |
6 |
Correct |
95 ms |
9760 KB |
Output is correct |
7 |
Correct |
126 ms |
9772 KB |
Output is correct |
8 |
Correct |
108 ms |
9840 KB |
Output is correct |
9 |
Correct |
99 ms |
9836 KB |
Output is correct |
10 |
Correct |
117 ms |
9760 KB |
Output is correct |
11 |
Correct |
128 ms |
10980 KB |
Output is correct |
12 |
Correct |
112 ms |
12348 KB |
Output is correct |
13 |
Correct |
101 ms |
11592 KB |
Output is correct |
14 |
Correct |
105 ms |
11784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2384 KB |
Output is correct |
2 |
Correct |
16 ms |
4184 KB |
Output is correct |
3 |
Correct |
24 ms |
6064 KB |
Output is correct |
4 |
Correct |
68 ms |
15164 KB |
Output is correct |
5 |
Correct |
76 ms |
15384 KB |
Output is correct |
6 |
Correct |
73 ms |
17100 KB |
Output is correct |
7 |
Correct |
70 ms |
18568 KB |
Output is correct |
8 |
Correct |
76 ms |
16148 KB |
Output is correct |
9 |
Correct |
74 ms |
16532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
13 ms |
1504 KB |
Output is correct |
3 |
Correct |
70 ms |
7760 KB |
Output is correct |
4 |
Correct |
90 ms |
9768 KB |
Output is correct |
5 |
Correct |
94 ms |
9760 KB |
Output is correct |
6 |
Correct |
102 ms |
10232 KB |
Output is correct |
7 |
Correct |
96 ms |
9776 KB |
Output is correct |
8 |
Correct |
96 ms |
9760 KB |
Output is correct |
9 |
Correct |
102 ms |
9852 KB |
Output is correct |
10 |
Correct |
100 ms |
9772 KB |
Output is correct |
11 |
Correct |
128 ms |
11236 KB |
Output is correct |
12 |
Correct |
108 ms |
12448 KB |
Output is correct |
13 |
Correct |
111 ms |
12408 KB |
Output is correct |
14 |
Correct |
129 ms |
11796 KB |
Output is correct |
15 |
Correct |
93 ms |
9764 KB |
Output is correct |
16 |
Correct |
90 ms |
9616 KB |
Output is correct |
17 |
Correct |
106 ms |
11512 KB |
Output is correct |
18 |
Correct |
108 ms |
12052 KB |
Output is correct |
19 |
Correct |
117 ms |
9772 KB |
Output is correct |
20 |
Correct |
97 ms |
12892 KB |
Output is correct |
21 |
Correct |
83 ms |
10260 KB |
Output is correct |
22 |
Correct |
82 ms |
9920 KB |
Output is correct |
23 |
Correct |
87 ms |
10008 KB |
Output is correct |
24 |
Correct |
101 ms |
10624 KB |
Output is correct |
25 |
Correct |
107 ms |
17708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
201 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
192 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |