#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define int long long
const int inf = 1e18+10;
const int maxn = 9e4+10;
int n, m, par[maxn];
vector<int> parid[maxn];
vector<int> g[maxn];
void find_pair(int32_t N, std::vector<int32_t> U, std::vector<int32_t> V, int32_t A, int32_t B) {
n = N;
m = U.size();
for(int i = 0; i < m; i++) {
g[U[i]].pb(i);
g[V[i]].pb(i);
}
vector<int32_t> vectudoa(m,0);
int tudoa = ask(vectudoa);
int path = tudoa/A;
int edgein = -1;
int lbs,rbs;
vector<int32_t> vectoll(m,0);
lbs = 0;
rbs = m-1;
while(lbs <= rbs) {
int mid = (lbs+rbs)/2;
vectoll.clear(); vectoll.resize(m,0);
for(int i = 0; i <= mid; i++) {
vectoll[i] = 1;
}
int toll = ask(vectoll);
if(toll != tudoa) {
edgein = mid;
rbs = mid-1;
}
else {
lbs = mid+1;
}
}
assert(edgein != -1);
int ss = U[edgein];
int tt = V[edgein];
vector<pair<int,int>> d(n+10,mp(inf,0));
d[ss] = mp(0,ss); par[ss] = -1;
d[tt] = mp(0,tt); par[tt] = -1;
queue<int> q; q.push(ss); q.push(tt);
while(q.size()) {
int u = q.front(); q.pop();
for(auto id : g[u]) {
int v = U[id]+V[id]-u;
if(d[v].fr > d[u].fr+1) {
d[v] = mp(d[u].fr+1,d[u].sc);
par[v] = u;
parid[v].clear(); parid[v].pb(id);
q.push(v);
}
else if(d[v].fr == d[u].fr+1 && d[v].sc != d[u].sc) {
parid[v].pb(id);
d[v].sc = -1;
}
else if(d[v].fr == d[u].fr+1) {
parid[v].pb(id);
}
}
}
int toll0;
vector<pair<int,int>> Ds;
for(int i = 0; i < n; i++) {
if(d[i].sc == ss) {
Ds.pb(mp(d[i].fr,i));
}
}
vector<pair<int,int>> Dt;
for(int i = 0; i < n; i++) {
if(d[i].sc == tt) {
Dt.pb(mp(d[i].fr,i));
}
}
sort(all(Dt));
sort(all(Ds));
lbs = 0;
rbs = (int) Ds.size()-1;
int32_t s = ss;
while(lbs <= rbs) {
int mid = (lbs+rbs)/2;
vectoll.clear(); vectoll.resize(m,1);
// for(int i = 0; i <= mid; i++) {
// if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 0;
// }
vectoll[edgein] = 0;
for(int i = 0; i < Dt.size(); i++) {
for(auto id : parid[Dt[i].sc]) vectoll[id] = 0;
}
for(int i = 0; i <= mid; i++) {
for(auto id : parid[Ds[i].sc]) vectoll[id] = 0;
// if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 1;
}
int toll = ask(vectoll);
if(toll == path*A) {
s = Ds[mid].sc;
rbs = mid-1;
}
else {
lbs = mid+1;
}
}
lbs = 0;
rbs = (int) Dt.size()-1;
int32_t t = tt;
while(lbs <= rbs) {
int mid = (lbs+rbs)/2;
vectoll.clear(); vectoll.resize(m,1);
vectoll[edgein] = 0;
for(int i = 0; i < Ds.size(); i++) {
for(auto id : parid[Ds[i].sc]) vectoll[id] = 0;
}
for(int i = 0; i <= mid; i++) {
for(auto id : parid[Dt[i].sc]) vectoll[id] = 0;
// if(parid[Dt[i].sc] != -1) vectoll[parid[Dt[i].sc]] = 1;
}
int toll = ask(vectoll);
if(toll == path*A) {
t = Dt[mid].sc;
rbs = mid-1;
}
else {
lbs = mid+1;
}
}
// cout << ss << " " << tt << endl;
// cout << s << " " << t << endl;
answer(s,t);
}
Compilation message
highway.cpp: In function 'void find_pair(int32_t, std::vector<int>, std::vector<int>, int32_t, int32_t)':
highway.cpp:111:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | for(int i = 0; i < Dt.size(); i++) {
| ~~^~~~~~~~~~~
highway.cpp:141:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for(int i = 0; i < Ds.size(); i++) {
| ~~^~~~~~~~~~~
highway.cpp:82:6: warning: unused variable 'toll0' [-Wunused-variable]
82 | int toll0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4456 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
11 |
Correct |
3 ms |
4476 KB |
Output is correct |
12 |
Correct |
2 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4560 KB |
Output is correct |
2 |
Correct |
11 ms |
6040 KB |
Output is correct |
3 |
Correct |
133 ms |
17104 KB |
Output is correct |
4 |
Correct |
147 ms |
17044 KB |
Output is correct |
5 |
Correct |
145 ms |
17056 KB |
Output is correct |
6 |
Correct |
136 ms |
17092 KB |
Output is correct |
7 |
Correct |
133 ms |
17172 KB |
Output is correct |
8 |
Correct |
123 ms |
17108 KB |
Output is correct |
9 |
Correct |
101 ms |
17048 KB |
Output is correct |
10 |
Correct |
115 ms |
17212 KB |
Output is correct |
11 |
Correct |
160 ms |
16728 KB |
Output is correct |
12 |
Correct |
128 ms |
16504 KB |
Output is correct |
13 |
Correct |
128 ms |
16592 KB |
Output is correct |
14 |
Correct |
129 ms |
16476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5968 KB |
Output is correct |
2 |
Correct |
16 ms |
7244 KB |
Output is correct |
3 |
Correct |
32 ms |
8464 KB |
Output is correct |
4 |
Correct |
77 ms |
16396 KB |
Output is correct |
5 |
Correct |
81 ms |
16424 KB |
Output is correct |
6 |
Correct |
85 ms |
16808 KB |
Output is correct |
7 |
Correct |
108 ms |
16552 KB |
Output is correct |
8 |
Correct |
83 ms |
16024 KB |
Output is correct |
9 |
Correct |
90 ms |
16512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4560 KB |
Output is correct |
2 |
Correct |
15 ms |
5892 KB |
Output is correct |
3 |
Correct |
107 ms |
14784 KB |
Output is correct |
4 |
Correct |
120 ms |
17108 KB |
Output is correct |
5 |
Correct |
101 ms |
17052 KB |
Output is correct |
6 |
Correct |
97 ms |
17064 KB |
Output is correct |
7 |
Correct |
90 ms |
17108 KB |
Output is correct |
8 |
Correct |
98 ms |
17108 KB |
Output is correct |
9 |
Correct |
177 ms |
17116 KB |
Output is correct |
10 |
Correct |
132 ms |
17040 KB |
Output is correct |
11 |
Correct |
128 ms |
16524 KB |
Output is correct |
12 |
Correct |
144 ms |
16728 KB |
Output is correct |
13 |
Correct |
171 ms |
16568 KB |
Output is correct |
14 |
Correct |
149 ms |
16332 KB |
Output is correct |
15 |
Correct |
117 ms |
17116 KB |
Output is correct |
16 |
Correct |
108 ms |
17096 KB |
Output is correct |
17 |
Correct |
147 ms |
16496 KB |
Output is correct |
18 |
Correct |
127 ms |
16496 KB |
Output is correct |
19 |
Correct |
137 ms |
17076 KB |
Output is correct |
20 |
Correct |
114 ms |
16596 KB |
Output is correct |
21 |
Correct |
97 ms |
18016 KB |
Output is correct |
22 |
Correct |
110 ms |
18016 KB |
Output is correct |
23 |
Correct |
125 ms |
17676 KB |
Output is correct |
24 |
Correct |
116 ms |
17528 KB |
Output is correct |
25 |
Correct |
135 ms |
16608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5908 KB |
Output is correct |
2 |
Correct |
13 ms |
6096 KB |
Output is correct |
3 |
Correct |
138 ms |
17556 KB |
Output is correct |
4 |
Correct |
182 ms |
17464 KB |
Output is correct |
5 |
Correct |
161 ms |
18852 KB |
Output is correct |
6 |
Correct |
215 ms |
17944 KB |
Output is correct |
7 |
Correct |
162 ms |
17944 KB |
Output is correct |
8 |
Correct |
193 ms |
18164 KB |
Output is correct |
9 |
Correct |
116 ms |
13048 KB |
Output is correct |
10 |
Correct |
122 ms |
13144 KB |
Output is correct |
11 |
Correct |
107 ms |
14668 KB |
Output is correct |
12 |
Correct |
166 ms |
16288 KB |
Output is correct |
13 |
Correct |
204 ms |
17408 KB |
Output is correct |
14 |
Correct |
169 ms |
18080 KB |
Output is correct |
15 |
Correct |
202 ms |
17992 KB |
Output is correct |
16 |
Correct |
155 ms |
14116 KB |
Output is correct |
17 |
Correct |
108 ms |
18052 KB |
Output is correct |
18 |
Correct |
109 ms |
18292 KB |
Output is correct |
19 |
Correct |
134 ms |
18280 KB |
Output is correct |
20 |
Correct |
135 ms |
18236 KB |
Output is correct |
21 |
Correct |
189 ms |
18876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
5968 KB |
Output is correct |
2 |
Correct |
19 ms |
6128 KB |
Output is correct |
3 |
Correct |
137 ms |
16904 KB |
Output is correct |
4 |
Correct |
138 ms |
17004 KB |
Output is correct |
5 |
Correct |
158 ms |
17148 KB |
Output is correct |
6 |
Correct |
197 ms |
18212 KB |
Output is correct |
7 |
Correct |
167 ms |
17476 KB |
Output is correct |
8 |
Correct |
143 ms |
17744 KB |
Output is correct |
9 |
Correct |
162 ms |
17424 KB |
Output is correct |
10 |
Correct |
154 ms |
18088 KB |
Output is correct |
11 |
Correct |
153 ms |
18668 KB |
Output is correct |
12 |
Correct |
168 ms |
18208 KB |
Output is correct |
13 |
Correct |
136 ms |
14648 KB |
Output is correct |
14 |
Correct |
136 ms |
13060 KB |
Output is correct |
15 |
Correct |
103 ms |
14696 KB |
Output is correct |
16 |
Correct |
101 ms |
13136 KB |
Output is correct |
17 |
Correct |
136 ms |
14600 KB |
Output is correct |
18 |
Correct |
125 ms |
12984 KB |
Output is correct |
19 |
Correct |
163 ms |
16392 KB |
Output is correct |
20 |
Correct |
159 ms |
17352 KB |
Output is correct |
21 |
Correct |
211 ms |
17924 KB |
Output is correct |
22 |
Correct |
173 ms |
18184 KB |
Output is correct |
23 |
Correct |
194 ms |
18484 KB |
Output is correct |
24 |
Correct |
168 ms |
18128 KB |
Output is correct |
25 |
Correct |
169 ms |
18204 KB |
Output is correct |
26 |
Correct |
166 ms |
18196 KB |
Output is correct |
27 |
Correct |
150 ms |
18208 KB |
Output is correct |
28 |
Correct |
104 ms |
18084 KB |
Output is correct |
29 |
Correct |
123 ms |
18328 KB |
Output is correct |
30 |
Correct |
141 ms |
18208 KB |
Output is correct |
31 |
Correct |
115 ms |
18144 KB |
Output is correct |
32 |
Correct |
118 ms |
17964 KB |
Output is correct |
33 |
Correct |
122 ms |
18332 KB |
Output is correct |
34 |
Correct |
160 ms |
18120 KB |
Output is correct |
35 |
Correct |
116 ms |
18148 KB |
Output is correct |
36 |
Correct |
119 ms |
18012 KB |
Output is correct |
37 |
Correct |
147 ms |
18200 KB |
Output is correct |
38 |
Correct |
109 ms |
18168 KB |
Output is correct |
39 |
Correct |
175 ms |
18900 KB |
Output is correct |
40 |
Correct |
169 ms |
18648 KB |
Output is correct |
41 |
Correct |
168 ms |
18724 KB |
Output is correct |
42 |
Correct |
196 ms |
18508 KB |
Output is correct |