#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll=long long;
using pii=pair<int,int>;
#define f first
#define s second
int n,m;
pii edge[130005];
vector<pii> graph[90005];
vector<int> tmp,ans;
ll mn_ask,dist;
bitset<90005> vis;
int tour[90005];
int solve1(int U){
int id=0;
queue<int> q;
q.emplace(U);
vis=0;
vis[U]=1;
tour[U]=0;
while(q.size()){
int u=q.front(); q.pop();
for(auto &[v,i]:graph[u]){
if(vis[v]) continue;
vis[v]=1;
q.emplace(v);
tour[v]=++id;
}
}
int l=dist,r=id;
while(l<r){
int mid=l+r>>1;
for(int i=0;i<m;++i){
auto &[u,v]=edge[i];
if(tour[u]<=mid&&tour[v]<=mid) tmp[i]=0;
else tmp[i]=1;
}
if(ask(tmp)==mn_ask) r=mid;
else l=mid+1;
}
for(int i=0;i<n;++i){
if(tour[i]==l){
ans.eb(i);
return i;
}
}
}
int solve2(int U){
int id=0;
queue<int> q;
q.emplace(U);
vis=0;
vis[U]=1;
tour[U]=0;
while(q.size()){
int u=q.front(); q.pop();
for(auto &[v,i]:graph[u]){
if(vis[v]) continue;
vis[v]=1;
q.emplace(v);
tour[v]=++id;
}
}
int l=dist,r=id;
while(l<r){
int mid=l+r>>1;
for(int i=0;i<m;++i){
auto &[u,v]=edge[i];
if(tour[u]<=mid&&tour[v]<=mid) tmp[i]=0;
else tmp[i]=1;
}
if(ask(tmp)==mn_ask) r=mid;
else l=mid+1;
}
for(int i=0;i<n;++i){
if(tour[i]==l){
ans.eb(i);
return i;
}
}
}
void solve3(int U){
queue<pii> q;
q.emplace(U,0);
vis=0;
vis[U]=1;
vector<int> tmp2(tmp.size(),1);
vector<pii> vec;
while(q.size()){
auto [u,d]=q.front(); q.pop();
for(auto &[v,id]:graph[u]){
if(vis[v]) continue;
if(d+1<dist) q.emplace(v,d+1), tmp2[id]=0;
else if(d+1==dist) vec.eb(v,id);
vis[v]=1;
}
}
int l=0,r=vec.size();
while(l<r){
int mid=l+r>>1;
tmp=tmp2;
for(int i=0;i<=mid;++i) tmp[vec[i].s]=0;
if(ask(tmp)==mn_ask) r=mid;
else l=mid+1;
}
ans.eb(vec[l].f);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
n=N,m=U.size();
for(int i=0;i<m;++i){
edge[i]={U[i],V[i]};
graph[U[i]].eb(V[i],i);
graph[V[i]].eb(U[i],i);
}
tmp.assign(m,0);
mn_ask=ask(tmp), dist=mn_ask/A;
solve3(solve2(solve1(0)));
answer(ans[1],ans[2]);
}
/*
15 15 99 100 9 10
0 1
1 3
3 5
5 7
7 9
9 11
11 13
13 14
14 12
12 10
10 8
8 6
6 4
4 2
2 0
*/
Compilation message
highway.cpp: In function 'int solve1(int)':
highway.cpp:36:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int mid=l+r>>1;
| ~^~
highway.cpp: In function 'int solve2(int)':
highway.cpp:70:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int mid=l+r>>1;
| ~^~
highway.cpp: In function 'void solve3(int)':
highway.cpp:104:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
104 | int mid=l+r>>1;
| ~^~
highway.cpp: In function 'int solve1(int)':
highway.cpp:20:16: warning: control reaches end of non-void function [-Wreturn-type]
20 | queue<int> q;
| ^
highway.cpp: In function 'int solve2(int)':
highway.cpp:54:16: warning: control reaches end of non-void function [-Wreturn-type]
54 | queue<int> q;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2752 KB |
Output is correct |
2 |
Correct |
1 ms |
2752 KB |
Output is correct |
3 |
Correct |
1 ms |
2752 KB |
Output is correct |
4 |
Correct |
1 ms |
2756 KB |
Output is correct |
5 |
Correct |
1 ms |
2752 KB |
Output is correct |
6 |
Correct |
1 ms |
2756 KB |
Output is correct |
7 |
Correct |
1 ms |
2752 KB |
Output is correct |
8 |
Correct |
1 ms |
2904 KB |
Output is correct |
9 |
Correct |
1 ms |
2756 KB |
Output is correct |
10 |
Correct |
1 ms |
2756 KB |
Output is correct |
11 |
Correct |
1 ms |
2752 KB |
Output is correct |
12 |
Correct |
1 ms |
2752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2820 KB |
Output is correct |
2 |
Correct |
10 ms |
3460 KB |
Output is correct |
3 |
Correct |
126 ms |
9872 KB |
Output is correct |
4 |
Correct |
108 ms |
9400 KB |
Output is correct |
5 |
Correct |
110 ms |
10028 KB |
Output is correct |
6 |
Correct |
98 ms |
9468 KB |
Output is correct |
7 |
Correct |
103 ms |
9980 KB |
Output is correct |
8 |
Correct |
104 ms |
9656 KB |
Output is correct |
9 |
Correct |
88 ms |
9616 KB |
Output is correct |
10 |
Correct |
109 ms |
9632 KB |
Output is correct |
11 |
Correct |
97 ms |
8788 KB |
Output is correct |
12 |
Correct |
108 ms |
9272 KB |
Output is correct |
13 |
Correct |
98 ms |
9256 KB |
Output is correct |
14 |
Correct |
88 ms |
9160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
3464 KB |
Output is correct |
2 |
Correct |
13 ms |
4088 KB |
Output is correct |
3 |
Correct |
22 ms |
4744 KB |
Output is correct |
4 |
Correct |
63 ms |
8560 KB |
Output is correct |
5 |
Correct |
70 ms |
8556 KB |
Output is correct |
6 |
Correct |
66 ms |
8548 KB |
Output is correct |
7 |
Correct |
75 ms |
8552 KB |
Output is correct |
8 |
Correct |
67 ms |
8548 KB |
Output is correct |
9 |
Correct |
69 ms |
8552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2820 KB |
Output is correct |
2 |
Correct |
11 ms |
3616 KB |
Output is correct |
3 |
Correct |
66 ms |
8020 KB |
Output is correct |
4 |
Correct |
94 ms |
9256 KB |
Output is correct |
5 |
Correct |
90 ms |
9384 KB |
Output is correct |
6 |
Correct |
83 ms |
9392 KB |
Output is correct |
7 |
Correct |
85 ms |
9396 KB |
Output is correct |
8 |
Correct |
103 ms |
9376 KB |
Output is correct |
9 |
Correct |
110 ms |
9456 KB |
Output is correct |
10 |
Correct |
121 ms |
9796 KB |
Output is correct |
11 |
Correct |
104 ms |
9020 KB |
Output is correct |
12 |
Correct |
86 ms |
8784 KB |
Output is correct |
13 |
Correct |
113 ms |
8560 KB |
Output is correct |
14 |
Correct |
115 ms |
9016 KB |
Output is correct |
15 |
Correct |
86 ms |
9268 KB |
Output is correct |
16 |
Correct |
89 ms |
9860 KB |
Output is correct |
17 |
Correct |
110 ms |
9028 KB |
Output is correct |
18 |
Correct |
100 ms |
8564 KB |
Output is correct |
19 |
Correct |
75 ms |
9396 KB |
Output is correct |
20 |
Correct |
87 ms |
8556 KB |
Output is correct |
21 |
Correct |
77 ms |
10560 KB |
Output is correct |
22 |
Correct |
82 ms |
10564 KB |
Output is correct |
23 |
Correct |
109 ms |
10612 KB |
Output is correct |
24 |
Correct |
92 ms |
10476 KB |
Output is correct |
25 |
Correct |
99 ms |
8780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3564 KB |
Output is correct |
2 |
Correct |
21 ms |
3656 KB |
Output is correct |
3 |
Correct |
130 ms |
10212 KB |
Output is correct |
4 |
Correct |
131 ms |
11036 KB |
Output is correct |
5 |
Correct |
183 ms |
12720 KB |
Output is correct |
6 |
Correct |
156 ms |
12724 KB |
Output is correct |
7 |
Correct |
169 ms |
12728 KB |
Output is correct |
8 |
Correct |
154 ms |
12068 KB |
Output is correct |
9 |
Correct |
129 ms |
10524 KB |
Output is correct |
10 |
Correct |
141 ms |
11180 KB |
Output is correct |
11 |
Correct |
138 ms |
11276 KB |
Output is correct |
12 |
Correct |
140 ms |
12324 KB |
Output is correct |
13 |
Correct |
160 ms |
12428 KB |
Output is correct |
14 |
Correct |
170 ms |
12096 KB |
Output is correct |
15 |
Correct |
207 ms |
12632 KB |
Output is correct |
16 |
Correct |
185 ms |
11804 KB |
Output is correct |
17 |
Correct |
105 ms |
10304 KB |
Output is correct |
18 |
Correct |
106 ms |
10868 KB |
Output is correct |
19 |
Correct |
104 ms |
10664 KB |
Output is correct |
20 |
Correct |
98 ms |
10768 KB |
Output is correct |
21 |
Correct |
137 ms |
12304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3568 KB |
Output is correct |
2 |
Correct |
12 ms |
3544 KB |
Output is correct |
3 |
Correct |
145 ms |
10280 KB |
Output is correct |
4 |
Correct |
135 ms |
10780 KB |
Output is correct |
5 |
Correct |
129 ms |
11344 KB |
Output is correct |
6 |
Correct |
195 ms |
12248 KB |
Output is correct |
7 |
Correct |
118 ms |
10328 KB |
Output is correct |
8 |
Correct |
108 ms |
10692 KB |
Output is correct |
9 |
Correct |
123 ms |
10984 KB |
Output is correct |
10 |
Correct |
140 ms |
12396 KB |
Output is correct |
11 |
Correct |
163 ms |
12104 KB |
Output is correct |
12 |
Correct |
147 ms |
12468 KB |
Output is correct |
13 |
Correct |
157 ms |
11176 KB |
Output is correct |
14 |
Correct |
137 ms |
10748 KB |
Output is correct |
15 |
Correct |
145 ms |
11512 KB |
Output is correct |
16 |
Correct |
123 ms |
10984 KB |
Output is correct |
17 |
Correct |
131 ms |
11076 KB |
Output is correct |
18 |
Correct |
155 ms |
11504 KB |
Output is correct |
19 |
Correct |
166 ms |
12272 KB |
Output is correct |
20 |
Correct |
146 ms |
12352 KB |
Output is correct |
21 |
Correct |
235 ms |
12268 KB |
Output is correct |
22 |
Correct |
172 ms |
12568 KB |
Output is correct |
23 |
Correct |
147 ms |
11908 KB |
Output is correct |
24 |
Correct |
206 ms |
12468 KB |
Output is correct |
25 |
Correct |
201 ms |
12204 KB |
Output is correct |
26 |
Correct |
184 ms |
12452 KB |
Output is correct |
27 |
Correct |
119 ms |
11256 KB |
Output is correct |
28 |
Partially correct |
101 ms |
10564 KB |
Output is partially correct |
29 |
Partially correct |
141 ms |
10880 KB |
Output is partially correct |
30 |
Partially correct |
139 ms |
11152 KB |
Output is partially correct |
31 |
Partially correct |
129 ms |
10820 KB |
Output is partially correct |
32 |
Correct |
99 ms |
11216 KB |
Output is correct |
33 |
Correct |
137 ms |
11460 KB |
Output is correct |
34 |
Partially correct |
107 ms |
10676 KB |
Output is partially correct |
35 |
Partially correct |
95 ms |
10688 KB |
Output is partially correct |
36 |
Correct |
113 ms |
10736 KB |
Output is correct |
37 |
Partially correct |
108 ms |
11056 KB |
Output is partially correct |
38 |
Partially correct |
117 ms |
11340 KB |
Output is partially correct |
39 |
Correct |
141 ms |
12304 KB |
Output is correct |
40 |
Correct |
151 ms |
11620 KB |
Output is correct |
41 |
Correct |
163 ms |
12300 KB |
Output is correct |
42 |
Correct |
139 ms |
11548 KB |
Output is correct |