#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){
graph[i].clear();
if(tour[i]==l) ans.eb(i);
}
for(int i=0;i<m;++i){
auto &[u,v]=edge[i];
if(tour[u]<=l&&tour[v]<=l) graph[u].eb(v,i),graph[v].eb(u,i);
}
return ans.back();
}
void solve3(int U){
using A=tuple<int,int,bool>;
queue<A> q;
q.emplace(U,0,0);
vis=0;
vis[U]=1;
vector<int> tmp2(tmp.size(),1);
vector<pii> vec;
while(q.size()){
auto [u,d,ok]=q.front(); q.pop();
for(auto &[v,id]:graph[u]){
if(vis[v]) continue;
bool ok2=ok|(v==ans[0]);
if(d+1<dist) q.emplace(v,d+1,ok2), tmp2[id]=0;
else if(d+1==dist&&ok2) vec.eb(v,id);
vis[v]=1;
}
}
int l=0,r=(int)vec.size()-1;
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:109:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
109 | 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;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2752 KB |
Output is correct |
3 |
Correct |
1 ms |
2760 KB |
Output is correct |
4 |
Correct |
1 ms |
2760 KB |
Output is correct |
5 |
Correct |
1 ms |
2760 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 |
2752 KB |
Output is correct |
9 |
Correct |
1 ms |
2752 KB |
Output is correct |
10 |
Correct |
1 ms |
2748 KB |
Output is correct |
11 |
Correct |
1 ms |
2752 KB |
Output is correct |
12 |
Correct |
1 ms |
2756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2816 KB |
Output is correct |
2 |
Correct |
10 ms |
3480 KB |
Output is correct |
3 |
Correct |
110 ms |
9756 KB |
Output is correct |
4 |
Correct |
95 ms |
9528 KB |
Output is correct |
5 |
Correct |
133 ms |
9520 KB |
Output is correct |
6 |
Correct |
97 ms |
9720 KB |
Output is correct |
7 |
Correct |
98 ms |
9536 KB |
Output is correct |
8 |
Correct |
152 ms |
9548 KB |
Output is correct |
9 |
Correct |
118 ms |
9292 KB |
Output is correct |
10 |
Correct |
142 ms |
9296 KB |
Output is correct |
11 |
Correct |
116 ms |
8676 KB |
Output is correct |
12 |
Correct |
117 ms |
9640 KB |
Output is correct |
13 |
Correct |
121 ms |
8932 KB |
Output is correct |
14 |
Correct |
97 ms |
8940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3416 KB |
Output is correct |
2 |
Correct |
20 ms |
3996 KB |
Output is correct |
3 |
Correct |
29 ms |
4628 KB |
Output is correct |
4 |
Correct |
87 ms |
8460 KB |
Output is correct |
5 |
Correct |
64 ms |
8460 KB |
Output is correct |
6 |
Correct |
77 ms |
8460 KB |
Output is correct |
7 |
Correct |
68 ms |
8460 KB |
Output is correct |
8 |
Correct |
105 ms |
8456 KB |
Output is correct |
9 |
Correct |
75 ms |
8452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2812 KB |
Output is correct |
2 |
Correct |
9 ms |
3452 KB |
Output is correct |
3 |
Correct |
77 ms |
7764 KB |
Output is correct |
4 |
Correct |
87 ms |
9280 KB |
Output is correct |
5 |
Correct |
114 ms |
9052 KB |
Output is correct |
6 |
Correct |
90 ms |
9296 KB |
Output is correct |
7 |
Correct |
104 ms |
9744 KB |
Output is correct |
8 |
Correct |
101 ms |
9724 KB |
Output is correct |
9 |
Correct |
119 ms |
9756 KB |
Output is correct |
10 |
Correct |
156 ms |
9516 KB |
Output is correct |
11 |
Correct |
99 ms |
8700 KB |
Output is correct |
12 |
Correct |
107 ms |
8664 KB |
Output is correct |
13 |
Correct |
103 ms |
8688 KB |
Output is correct |
14 |
Correct |
99 ms |
8932 KB |
Output is correct |
15 |
Correct |
123 ms |
9500 KB |
Output is correct |
16 |
Correct |
94 ms |
9060 KB |
Output is correct |
17 |
Correct |
114 ms |
8456 KB |
Output is correct |
18 |
Correct |
138 ms |
8704 KB |
Output is correct |
19 |
Correct |
132 ms |
9276 KB |
Output is correct |
20 |
Correct |
94 ms |
8668 KB |
Output is correct |
21 |
Correct |
83 ms |
9792 KB |
Output is correct |
22 |
Correct |
83 ms |
9708 KB |
Output is correct |
23 |
Correct |
87 ms |
9836 KB |
Output is correct |
24 |
Correct |
85 ms |
9764 KB |
Output is correct |
25 |
Correct |
83 ms |
8820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3472 KB |
Output is correct |
2 |
Correct |
17 ms |
3540 KB |
Output is correct |
3 |
Correct |
132 ms |
10192 KB |
Output is correct |
4 |
Correct |
143 ms |
10480 KB |
Output is correct |
5 |
Correct |
146 ms |
11860 KB |
Output is correct |
6 |
Correct |
142 ms |
12076 KB |
Output is correct |
7 |
Correct |
168 ms |
11600 KB |
Output is correct |
8 |
Runtime error |
163 ms |
23444 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3572 KB |
Output is correct |
2 |
Correct |
19 ms |
3608 KB |
Output is correct |
3 |
Correct |
104 ms |
9788 KB |
Output is correct |
4 |
Correct |
142 ms |
10248 KB |
Output is correct |
5 |
Correct |
141 ms |
10508 KB |
Output is correct |
6 |
Correct |
160 ms |
12076 KB |
Output is correct |
7 |
Correct |
110 ms |
10256 KB |
Output is correct |
8 |
Correct |
118 ms |
9984 KB |
Output is correct |
9 |
Correct |
115 ms |
10276 KB |
Output is correct |
10 |
Correct |
132 ms |
11636 KB |
Output is correct |
11 |
Correct |
188 ms |
11864 KB |
Output is correct |
12 |
Correct |
146 ms |
11392 KB |
Output is correct |
13 |
Correct |
136 ms |
11132 KB |
Output is correct |
14 |
Correct |
124 ms |
10868 KB |
Output is correct |
15 |
Correct |
151 ms |
10644 KB |
Output is correct |
16 |
Correct |
140 ms |
10792 KB |
Output is correct |
17 |
Correct |
166 ms |
11004 KB |
Output is correct |
18 |
Correct |
132 ms |
10664 KB |
Output is correct |
19 |
Correct |
202 ms |
11892 KB |
Output is correct |
20 |
Correct |
150 ms |
11292 KB |
Output is correct |
21 |
Correct |
139 ms |
12360 KB |
Output is correct |
22 |
Correct |
139 ms |
12084 KB |
Output is correct |
23 |
Correct |
164 ms |
12072 KB |
Output is correct |
24 |
Correct |
176 ms |
12276 KB |
Output is correct |
25 |
Correct |
138 ms |
11628 KB |
Output is correct |
26 |
Correct |
174 ms |
11860 KB |
Output is correct |
27 |
Correct |
155 ms |
10040 KB |
Output is correct |
28 |
Correct |
136 ms |
9712 KB |
Output is correct |
29 |
Correct |
117 ms |
9912 KB |
Output is correct |
30 |
Correct |
98 ms |
9840 KB |
Output is correct |
31 |
Correct |
91 ms |
9920 KB |
Output is correct |
32 |
Correct |
127 ms |
10072 KB |
Output is correct |
33 |
Correct |
123 ms |
10092 KB |
Output is correct |
34 |
Correct |
92 ms |
9752 KB |
Output is correct |
35 |
Correct |
118 ms |
9788 KB |
Output is correct |
36 |
Correct |
108 ms |
9560 KB |
Output is correct |
37 |
Correct |
138 ms |
10260 KB |
Output is correct |
38 |
Correct |
102 ms |
10236 KB |
Output is correct |
39 |
Correct |
152 ms |
11368 KB |
Output is correct |
40 |
Correct |
160 ms |
11576 KB |
Output is correct |
41 |
Correct |
164 ms |
11608 KB |
Output is correct |
42 |
Correct |
157 ms |
11564 KB |
Output is correct |