#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
int dd[2][maxn];
vector<pii> edge[maxn];
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
vector<int> S(2,0),T(2,0);
int M=(int)U.size();
for(int i=0;i<M;i++){
edge[U[i]].push_back({V[i],i});
edge[V[i]].push_back({U[i],i});
}
vector<int> w(M,0);
ll dist=ask(w);
int l=1,r=M;
while(l<r){
int mid=(l+r)>>1;
w.assign(M,0);
for(int i=0;i<mid;i++) w[i]=1;
if(ask(w)!=dist) r=mid;
else l=mid+1;
}
S[0]=U[l-1],S[1]=V[l-1];
//cout << S[0] << ' ' << S[1] << '\n';
for(int i=0;i<=1;i++){
queue<int> qq;
for(int u=0;u<N;u++) dd[i][u]=-1;
dd[i][S[i]]=0;qq.push(S[i]);
while(!qq.empty()){
int u=qq.front();qq.pop();
for(auto [v,id]:edge[u]) if(dd[i][v]==-1){
dd[i][v]=dd[i][u]+1;
qq.push(v);
}
}
}
vector<vector<int>> cc(2);
for(int u=0;u<N;u++){
if(dd[0][u]<dd[1][u]) cc[0].push_back(u);
else if(dd[0][u]>dd[1][u]) cc[1].push_back(u);
}
for(int i=0;i<=1;i++){
sort(cc[i].begin(),cc[i].end(),[&](int x,int y){
return dd[i][x]>dd[i][y];
});
//for(int x:cc[i]) cout << x << ' ';
//cout << '\n';
T[i]=cc[i].back();
l=0,r=(int)cc[i].size()-2;
while(l<=r){
int mid=(l+r)>>1;
w.assign(M,0);
for(int j=0;j<=mid;j++) for(auto [v,id]:edge[cc[i][j]]) w[id]=1;
if(ask(w)!=dist) T[i]=cc[i][mid],r=mid-1;
else l=mid+1;
}
}
answer(T[0],T[1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2796 KB |
Output is correct |
2 |
Correct |
1 ms |
2804 KB |
Output is correct |
3 |
Correct |
1 ms |
2796 KB |
Output is correct |
4 |
Correct |
2 ms |
2796 KB |
Output is correct |
5 |
Correct |
1 ms |
2800 KB |
Output is correct |
6 |
Correct |
1 ms |
2800 KB |
Output is correct |
7 |
Correct |
2 ms |
2800 KB |
Output is correct |
8 |
Correct |
1 ms |
2800 KB |
Output is correct |
9 |
Correct |
1 ms |
2796 KB |
Output is correct |
10 |
Correct |
1 ms |
2804 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2856 KB |
Output is correct |
2 |
Correct |
11 ms |
3556 KB |
Output is correct |
3 |
Correct |
116 ms |
9624 KB |
Output is correct |
4 |
Correct |
112 ms |
9396 KB |
Output is correct |
5 |
Correct |
105 ms |
9380 KB |
Output is correct |
6 |
Correct |
135 ms |
9376 KB |
Output is correct |
7 |
Correct |
132 ms |
9868 KB |
Output is correct |
8 |
Correct |
151 ms |
9368 KB |
Output is correct |
9 |
Correct |
124 ms |
9624 KB |
Output is correct |
10 |
Correct |
109 ms |
9636 KB |
Output is correct |
11 |
Correct |
119 ms |
9592 KB |
Output is correct |
12 |
Correct |
126 ms |
9040 KB |
Output is correct |
13 |
Correct |
150 ms |
9256 KB |
Output is correct |
14 |
Correct |
118 ms |
8768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3496 KB |
Output is correct |
2 |
Correct |
23 ms |
4096 KB |
Output is correct |
3 |
Correct |
29 ms |
4944 KB |
Output is correct |
4 |
Correct |
73 ms |
8564 KB |
Output is correct |
5 |
Correct |
88 ms |
8560 KB |
Output is correct |
6 |
Correct |
114 ms |
8904 KB |
Output is correct |
7 |
Correct |
79 ms |
8756 KB |
Output is correct |
8 |
Correct |
76 ms |
9048 KB |
Output is correct |
9 |
Correct |
115 ms |
8648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2852 KB |
Output is correct |
2 |
Correct |
17 ms |
3532 KB |
Output is correct |
3 |
Correct |
120 ms |
8244 KB |
Output is correct |
4 |
Correct |
110 ms |
9364 KB |
Output is correct |
5 |
Correct |
104 ms |
9140 KB |
Output is correct |
6 |
Correct |
133 ms |
9384 KB |
Output is correct |
7 |
Correct |
118 ms |
9140 KB |
Output is correct |
8 |
Correct |
104 ms |
9360 KB |
Output is correct |
9 |
Correct |
157 ms |
9376 KB |
Output is correct |
10 |
Correct |
124 ms |
9608 KB |
Output is correct |
11 |
Correct |
127 ms |
9028 KB |
Output is correct |
12 |
Correct |
151 ms |
8988 KB |
Output is correct |
13 |
Correct |
114 ms |
8812 KB |
Output is correct |
14 |
Correct |
140 ms |
9236 KB |
Output is correct |
15 |
Correct |
106 ms |
9388 KB |
Output is correct |
16 |
Correct |
100 ms |
9152 KB |
Output is correct |
17 |
Correct |
120 ms |
8748 KB |
Output is correct |
18 |
Correct |
109 ms |
8800 KB |
Output is correct |
19 |
Correct |
150 ms |
9524 KB |
Output is correct |
20 |
Correct |
144 ms |
8992 KB |
Output is correct |
21 |
Correct |
80 ms |
9892 KB |
Output is correct |
22 |
Correct |
84 ms |
9892 KB |
Output is correct |
23 |
Correct |
124 ms |
10596 KB |
Output is correct |
24 |
Correct |
87 ms |
9884 KB |
Output is correct |
25 |
Correct |
118 ms |
8836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3436 KB |
Output is correct |
2 |
Correct |
13 ms |
3660 KB |
Output is correct |
3 |
Correct |
132 ms |
9968 KB |
Output is correct |
4 |
Correct |
185 ms |
10412 KB |
Output is correct |
5 |
Correct |
157 ms |
11032 KB |
Output is correct |
6 |
Correct |
166 ms |
11192 KB |
Output is correct |
7 |
Correct |
171 ms |
11668 KB |
Output is correct |
8 |
Correct |
145 ms |
11324 KB |
Output is correct |
9 |
Correct |
115 ms |
9368 KB |
Output is correct |
10 |
Correct |
134 ms |
9400 KB |
Output is correct |
11 |
Correct |
101 ms |
10156 KB |
Output is correct |
12 |
Correct |
199 ms |
11088 KB |
Output is correct |
13 |
Correct |
202 ms |
11092 KB |
Output is correct |
14 |
Correct |
177 ms |
11508 KB |
Output is correct |
15 |
Correct |
192 ms |
11012 KB |
Output is correct |
16 |
Correct |
136 ms |
9896 KB |
Output is correct |
17 |
Correct |
102 ms |
9596 KB |
Output is correct |
18 |
Correct |
128 ms |
10060 KB |
Output is correct |
19 |
Correct |
111 ms |
9504 KB |
Output is correct |
20 |
Correct |
115 ms |
9788 KB |
Output is correct |
21 |
Correct |
200 ms |
11084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3416 KB |
Output is correct |
2 |
Correct |
13 ms |
3616 KB |
Output is correct |
3 |
Correct |
149 ms |
10000 KB |
Output is correct |
4 |
Correct |
166 ms |
10624 KB |
Output is correct |
5 |
Correct |
148 ms |
10336 KB |
Output is correct |
6 |
Correct |
159 ms |
11520 KB |
Output is correct |
7 |
Correct |
169 ms |
9992 KB |
Output is correct |
8 |
Correct |
174 ms |
9908 KB |
Output is correct |
9 |
Correct |
163 ms |
10296 KB |
Output is correct |
10 |
Correct |
176 ms |
11536 KB |
Output is correct |
11 |
Correct |
202 ms |
11156 KB |
Output is correct |
12 |
Correct |
175 ms |
11308 KB |
Output is correct |
13 |
Correct |
124 ms |
9952 KB |
Output is correct |
14 |
Correct |
119 ms |
9388 KB |
Output is correct |
15 |
Correct |
134 ms |
9932 KB |
Output is correct |
16 |
Correct |
118 ms |
9600 KB |
Output is correct |
17 |
Correct |
126 ms |
9956 KB |
Output is correct |
18 |
Correct |
129 ms |
9908 KB |
Output is correct |
19 |
Correct |
209 ms |
11284 KB |
Output is correct |
20 |
Correct |
176 ms |
11260 KB |
Output is correct |
21 |
Correct |
200 ms |
11300 KB |
Output is correct |
22 |
Correct |
180 ms |
11768 KB |
Output is correct |
23 |
Correct |
191 ms |
11744 KB |
Output is correct |
24 |
Correct |
169 ms |
11708 KB |
Output is correct |
25 |
Correct |
174 ms |
11748 KB |
Output is correct |
26 |
Correct |
207 ms |
11328 KB |
Output is correct |
27 |
Correct |
103 ms |
9716 KB |
Output is correct |
28 |
Correct |
124 ms |
10340 KB |
Output is correct |
29 |
Correct |
132 ms |
10020 KB |
Output is correct |
30 |
Correct |
78 ms |
9496 KB |
Output is correct |
31 |
Correct |
138 ms |
9896 KB |
Output is correct |
32 |
Correct |
94 ms |
9600 KB |
Output is correct |
33 |
Correct |
106 ms |
9844 KB |
Output is correct |
34 |
Correct |
98 ms |
9724 KB |
Output is correct |
35 |
Correct |
120 ms |
9672 KB |
Output is correct |
36 |
Correct |
87 ms |
9804 KB |
Output is correct |
37 |
Correct |
125 ms |
9828 KB |
Output is correct |
38 |
Correct |
122 ms |
9996 KB |
Output is correct |
39 |
Correct |
188 ms |
11608 KB |
Output is correct |
40 |
Correct |
199 ms |
11316 KB |
Output is correct |
41 |
Correct |
147 ms |
11372 KB |
Output is correct |
42 |
Correct |
166 ms |
11820 KB |
Output is correct |