#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long ll;
int edgeCnt;
vector<vector<pair<int, int>>> adj;
vector<pair<int, pair<int, int>>> edges;
void find_distances(int index, int last, int dist){
dist += 1;
for (auto node : adj[index]){
if (node.first == last) continue;
edges.push_back({dist, node});
find_distances(node.first, index, dist);
}
}
int find_S(ll dist){
find_distances(0, 0, 0);
sort(edges.begin(), edges.end());
int l = 0, r = edgeCnt - 1;
while (l < r){
int c = (l + r + 1) / 2;
vector<int> w(edgeCnt);
for (int i = c; i <= r; i++)
w[edges[i].second.second] = 1;
ll cur_dist = ask(w);
if (cur_dist == dist)
r = c - 1;
else
l = c;
}
return edges[l].second.first;
}
int bfs_dist;
vector<pair<int, int>> sus_edges;
void find_sus_edges(int index, int last, int dist){
dist += 1;
for (auto node : adj[index]){
if (node.first == last) continue;
if (dist == bfs_dist)
sus_edges.push_back(node);
else
find_sus_edges(node.first, index, dist);
}
}
int find_T(int root, ll dist){
find_sus_edges(root, root, 0);
int l = 0, r = sus_edges.size() - 1;
while (l < r){
int c = (l + r + 1) / 2;
vector<int> w(edgeCnt);
for (int i = c; i <= r; i++)
w[sus_edges[i].second] = 1;
ll cur_dist = ask(w);
if (cur_dist == dist)
r = c - 1;
else
l = c;
}
return sus_edges[l].first;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
edgeCnt = U.size();
adj = vector<vector<pair<int, int>>>(N);
for (int i = 0; i < edgeCnt; i++){
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
ll dist = ask(vector<int>(edgeCnt));
bfs_dist = dist / A;
int S = find_S(dist);
int T = find_T(S, dist);
answer(S, T);
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1500 KB |
Output is correct |
3 |
Correct |
95 ms |
9240 KB |
Output is correct |
4 |
Correct |
77 ms |
9100 KB |
Output is correct |
5 |
Correct |
84 ms |
9104 KB |
Output is correct |
6 |
Correct |
73 ms |
9068 KB |
Output is correct |
7 |
Correct |
78 ms |
9084 KB |
Output is correct |
8 |
Correct |
79 ms |
9248 KB |
Output is correct |
9 |
Correct |
77 ms |
9068 KB |
Output is correct |
10 |
Correct |
81 ms |
9244 KB |
Output is correct |
11 |
Correct |
85 ms |
10892 KB |
Output is correct |
12 |
Correct |
74 ms |
11496 KB |
Output is correct |
13 |
Correct |
80 ms |
11136 KB |
Output is correct |
14 |
Correct |
78 ms |
10212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2536 KB |
Output is correct |
2 |
Correct |
15 ms |
4308 KB |
Output is correct |
3 |
Correct |
25 ms |
6352 KB |
Output is correct |
4 |
Correct |
76 ms |
18040 KB |
Output is correct |
5 |
Correct |
65 ms |
18024 KB |
Output is correct |
6 |
Correct |
65 ms |
18028 KB |
Output is correct |
7 |
Correct |
65 ms |
18024 KB |
Output is correct |
8 |
Correct |
61 ms |
17892 KB |
Output is correct |
9 |
Correct |
65 ms |
18040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1368 KB |
Output is correct |
3 |
Correct |
53 ms |
7492 KB |
Output is correct |
4 |
Correct |
69 ms |
9068 KB |
Output is correct |
5 |
Correct |
66 ms |
9068 KB |
Output is correct |
6 |
Correct |
65 ms |
9016 KB |
Output is correct |
7 |
Correct |
66 ms |
9072 KB |
Output is correct |
8 |
Correct |
76 ms |
9104 KB |
Output is correct |
9 |
Correct |
81 ms |
9168 KB |
Output is correct |
10 |
Correct |
78 ms |
9068 KB |
Output is correct |
11 |
Correct |
80 ms |
10172 KB |
Output is correct |
12 |
Correct |
88 ms |
12172 KB |
Output is correct |
13 |
Correct |
76 ms |
11372 KB |
Output is correct |
14 |
Correct |
74 ms |
11624 KB |
Output is correct |
15 |
Correct |
72 ms |
9068 KB |
Output is correct |
16 |
Correct |
74 ms |
9068 KB |
Output is correct |
17 |
Correct |
79 ms |
11644 KB |
Output is correct |
18 |
Correct |
73 ms |
10860 KB |
Output is correct |
19 |
Correct |
62 ms |
9068 KB |
Output is correct |
20 |
Correct |
75 ms |
12908 KB |
Output is correct |
21 |
Correct |
72 ms |
10352 KB |
Output is correct |
22 |
Correct |
82 ms |
10128 KB |
Output is correct |
23 |
Correct |
70 ms |
9516 KB |
Output is correct |
24 |
Correct |
88 ms |
10332 KB |
Output is correct |
25 |
Correct |
82 ms |
16628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
172 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
153 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |