#include<bits/stdc++.h>
#include "highway.h"
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii > vii;
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
const int N=2e5;
vii E[N], E2[N];
int dep[N], par[N];
vii edg;
vii pre[2];
void dfs(int v, int num){
for(pii ee:E2[v]){
int u=ee.st;
if(u!=par[v]){
pre[num].pb(ee);
par[u]=v;
dfs(u, num);
}
}
}
void find_pair(int n, std::vector<int> UU, std::vector<int> VV, int A, int B) {
int M = UU.size();
for(int i=0; i<M; i++){
edg.eb(UU[i],VV[i]);
E[UU[i]].eb(VV[i], i);
E[VV[i]].eb(UU[i], i );
}
vi w(M);
int dist=ask(w)/A;
int l=0, r=M;
while(l<r){
int m=(l+r)/2;
w.clear();
w.resize(m+1, 0);
w.resize(M, 1);
if(ask(w)==dist*1ll*A)r=m;
else l=m+1;
}
int root=l;
vi V;
V.pb(edg[root].st);
V.pb(edg[root].nd);
dep[V[0]]=dep[V[1]]=1;
vi drz={root};
for(int i=0; i<V.size(); i++){
int v=V[i];
for(pii ee:E[v]){
if(dep[ee.st]==0){
dep[ee.st]=dep[v]+1;
V.pb(ee.st);
E2[v].pb(ee);
drz.pb(ee.nd);
}
}
}
deb(root, dist);
par[V[0]]=V[1];
par[V[1]]=V[0];
dfs(V[0], 0);
dfs(V[1], 1);
int res[2];
for(int ii=0; ii<2; ii++){
int l=0, r=pre[ii].size();
for(auto ee:pre[ii]){
//deb(ee.st, ee.nd);
}
while(l<r){
int m=(l+r)>>1;
w.resize(0);
w.resize(M, 1);
w[root]=0;
for(auto ee:pre[ii^1])w[ee.nd]=0;
for(int i=0; i<m; i++)w[pre[ii][i].nd]=0;
//deb(m);
//for(int i:w){cerr<<i<<" ";}cerr<<"\n";
//deb(ask(w));
if(ask(w)==A*1ll*dist){
r=m;
}
else{
l=m+1;
}
}
if(l==0)res[ii]=V[ii];
else res[ii]=pre[ii][l-1].st;
deb(l, res[ii]);
}
answer(res[0], res[1]);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0; i<V.size(); i++){
| ~^~~~~~~~~
highway.cpp:80:12: warning: variable 'ee' set but not used [-Wunused-but-set-variable]
80 | for(auto ee:pre[ii]){
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
5 ms |
9680 KB |
Output is correct |
3 |
Correct |
5 ms |
9680 KB |
Output is correct |
4 |
Correct |
4 ms |
9680 KB |
Output is correct |
5 |
Correct |
4 ms |
9680 KB |
Output is correct |
6 |
Correct |
4 ms |
9608 KB |
Output is correct |
7 |
Correct |
4 ms |
9680 KB |
Output is correct |
8 |
Correct |
4 ms |
9716 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
5 ms |
9680 KB |
Output is correct |
11 |
Correct |
4 ms |
9680 KB |
Output is correct |
12 |
Correct |
5 ms |
9680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9808 KB |
Output is correct |
2 |
Correct |
15 ms |
10924 KB |
Output is correct |
3 |
Correct |
102 ms |
20092 KB |
Output is correct |
4 |
Correct |
134 ms |
20148 KB |
Output is correct |
5 |
Correct |
85 ms |
20140 KB |
Output is correct |
6 |
Correct |
97 ms |
20132 KB |
Output is correct |
7 |
Correct |
95 ms |
20096 KB |
Output is correct |
8 |
Correct |
114 ms |
20096 KB |
Output is correct |
9 |
Correct |
97 ms |
20400 KB |
Output is correct |
10 |
Correct |
107 ms |
20176 KB |
Output is correct |
11 |
Correct |
114 ms |
22396 KB |
Output is correct |
12 |
Correct |
124 ms |
23744 KB |
Output is correct |
13 |
Correct |
99 ms |
22792 KB |
Output is correct |
14 |
Correct |
106 ms |
23100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
11796 KB |
Output is correct |
2 |
Correct |
19 ms |
13320 KB |
Output is correct |
3 |
Correct |
33 ms |
15820 KB |
Output is correct |
4 |
Correct |
114 ms |
25256 KB |
Output is correct |
5 |
Correct |
75 ms |
25752 KB |
Output is correct |
6 |
Correct |
119 ms |
27160 KB |
Output is correct |
7 |
Correct |
95 ms |
28064 KB |
Output is correct |
8 |
Correct |
100 ms |
25760 KB |
Output is correct |
9 |
Correct |
97 ms |
26764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9808 KB |
Output is correct |
2 |
Correct |
12 ms |
10948 KB |
Output is correct |
3 |
Correct |
75 ms |
18416 KB |
Output is correct |
4 |
Correct |
113 ms |
20100 KB |
Output is correct |
5 |
Correct |
83 ms |
20144 KB |
Output is correct |
6 |
Correct |
95 ms |
20092 KB |
Output is correct |
7 |
Correct |
80 ms |
20184 KB |
Output is correct |
8 |
Correct |
90 ms |
20172 KB |
Output is correct |
9 |
Correct |
115 ms |
19648 KB |
Output is correct |
10 |
Correct |
128 ms |
20140 KB |
Output is correct |
11 |
Correct |
98 ms |
22456 KB |
Output is correct |
12 |
Correct |
125 ms |
23356 KB |
Output is correct |
13 |
Correct |
128 ms |
22376 KB |
Output is correct |
14 |
Correct |
125 ms |
22860 KB |
Output is correct |
15 |
Correct |
114 ms |
20156 KB |
Output is correct |
16 |
Correct |
125 ms |
20088 KB |
Output is correct |
17 |
Correct |
150 ms |
22912 KB |
Output is correct |
18 |
Correct |
88 ms |
23104 KB |
Output is correct |
19 |
Correct |
83 ms |
20172 KB |
Output is correct |
20 |
Correct |
102 ms |
23944 KB |
Output is correct |
21 |
Correct |
74 ms |
20240 KB |
Output is correct |
22 |
Correct |
70 ms |
20232 KB |
Output is correct |
23 |
Correct |
113 ms |
19304 KB |
Output is correct |
24 |
Correct |
81 ms |
20056 KB |
Output is correct |
25 |
Correct |
98 ms |
27200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
10960 KB |
Output is correct |
2 |
Correct |
15 ms |
10988 KB |
Output is correct |
3 |
Correct |
106 ms |
20348 KB |
Output is correct |
4 |
Correct |
122 ms |
21036 KB |
Output is correct |
5 |
Correct |
181 ms |
21688 KB |
Output is correct |
6 |
Correct |
134 ms |
21988 KB |
Output is correct |
7 |
Correct |
154 ms |
21928 KB |
Output is correct |
8 |
Correct |
164 ms |
21484 KB |
Output is correct |
9 |
Correct |
167 ms |
17572 KB |
Output is correct |
10 |
Correct |
124 ms |
18024 KB |
Output is correct |
11 |
Correct |
99 ms |
19080 KB |
Output is correct |
12 |
Correct |
161 ms |
20444 KB |
Output is correct |
13 |
Correct |
168 ms |
21548 KB |
Output is correct |
14 |
Correct |
135 ms |
21784 KB |
Output is correct |
15 |
Correct |
183 ms |
22024 KB |
Output is correct |
16 |
Correct |
158 ms |
18872 KB |
Output is correct |
17 |
Correct |
81 ms |
19876 KB |
Output is correct |
18 |
Correct |
113 ms |
20176 KB |
Output is correct |
19 |
Correct |
116 ms |
19984 KB |
Output is correct |
20 |
Correct |
98 ms |
20252 KB |
Output is correct |
21 |
Correct |
126 ms |
22996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
10788 KB |
Output is correct |
2 |
Correct |
18 ms |
10960 KB |
Output is correct |
3 |
Correct |
110 ms |
20624 KB |
Output is correct |
4 |
Correct |
118 ms |
20556 KB |
Output is correct |
5 |
Correct |
109 ms |
21016 KB |
Output is correct |
6 |
Correct |
179 ms |
21908 KB |
Output is correct |
7 |
Correct |
103 ms |
20612 KB |
Output is correct |
8 |
Correct |
102 ms |
20580 KB |
Output is correct |
9 |
Correct |
129 ms |
21024 KB |
Output is correct |
10 |
Correct |
178 ms |
21924 KB |
Output is correct |
11 |
Correct |
135 ms |
21456 KB |
Output is correct |
12 |
Correct |
134 ms |
21884 KB |
Output is correct |
13 |
Correct |
97 ms |
19080 KB |
Output is correct |
14 |
Correct |
116 ms |
18016 KB |
Output is correct |
15 |
Correct |
95 ms |
19092 KB |
Output is correct |
16 |
Correct |
97 ms |
18116 KB |
Output is correct |
17 |
Correct |
101 ms |
19080 KB |
Output is correct |
18 |
Correct |
109 ms |
17996 KB |
Output is correct |
19 |
Correct |
182 ms |
20528 KB |
Output is correct |
20 |
Correct |
210 ms |
21080 KB |
Output is correct |
21 |
Correct |
152 ms |
22048 KB |
Output is correct |
22 |
Correct |
207 ms |
21524 KB |
Output is correct |
23 |
Correct |
137 ms |
21772 KB |
Output is correct |
24 |
Correct |
160 ms |
22044 KB |
Output is correct |
25 |
Correct |
145 ms |
21780 KB |
Output is correct |
26 |
Correct |
133 ms |
22008 KB |
Output is correct |
27 |
Correct |
79 ms |
20284 KB |
Output is correct |
28 |
Correct |
81 ms |
19900 KB |
Output is correct |
29 |
Correct |
91 ms |
20452 KB |
Output is correct |
30 |
Correct |
88 ms |
20056 KB |
Output is correct |
31 |
Correct |
84 ms |
20004 KB |
Output is correct |
32 |
Correct |
109 ms |
19828 KB |
Output is correct |
33 |
Correct |
82 ms |
20304 KB |
Output is correct |
34 |
Correct |
105 ms |
20176 KB |
Output is correct |
35 |
Correct |
123 ms |
20120 KB |
Output is correct |
36 |
Correct |
86 ms |
19812 KB |
Output is correct |
37 |
Correct |
79 ms |
20420 KB |
Output is correct |
38 |
Correct |
82 ms |
20144 KB |
Output is correct |
39 |
Correct |
134 ms |
23360 KB |
Output is correct |
40 |
Correct |
130 ms |
23580 KB |
Output is correct |
41 |
Correct |
161 ms |
22704 KB |
Output is correct |
42 |
Correct |
193 ms |
22116 KB |
Output is correct |