#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], 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) {
// int M = U.size();
// for (int j = 0; j < 50; ++j) {
// std::vector<int> w(M);
// for (int i = 0; i < M; ++i) {
// w[i] = 0;
// }
// long long toll = ask(w);
// }
// answer(0, N - 1);
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; parid[ss] = -1;
d[tt] = mp(0,tt); par[tt] = -1; parid[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] = id;
q.push(v);
}
}
}
vector<pair<int,int>> Ds;
for(int i = 0; i < n; i++) {
if(d[i].sc == ss) {
Ds.pb(mp(d[i].fr,i));
}
}
sort(all(Ds));
lbs = 0;
rbs = (int) Ds.size()-1;
int32_t s = -1;
while(lbs <= rbs) {
int mid = (lbs+rbs)/2;
vectoll.clear(); vectoll.resize(m,0);
for(int i = 0; i <= mid; i++) {
if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 0;
}
for(int i = mid+1; i < (int) Ds.size(); i++) {
if(parid[Ds[i].sc] != -1) vectoll[parid[Ds[i].sc]] = 1;
}
int toll = ask(vectoll);
if(toll == tudoa) {
s = Ds[mid].sc;
rbs = mid-1;
}
else {
lbs = mid+1;
}
}
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));
lbs = 0;
rbs = (int) Dt.size()-1;
int32_t t = -1;
while(lbs <= rbs) {
int mid = (lbs+rbs)/2;
vectoll.clear(); vectoll.resize(m,0);
for(int i = 0; i <= mid; i++) {
if(parid[Dt[i].sc] != -1) vectoll[parid[Dt[i].sc]] = 0;
}
for(int i = mid+1; i < (int) Dt.size(); i++) {
if(parid[Dt[i].sc] != -1) vectoll[parid[Dt[i].sc]] = 1;
}
int toll = ask(vectoll);
if(toll == tudoa) {
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:36:6: warning: unused variable 'path' [-Wunused-variable]
36 | int path = tudoa/A;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2424 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2416 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
2420 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2512 KB |
Output is correct |
2 |
Correct |
34 ms |
3628 KB |
Output is correct |
3 |
Correct |
133 ms |
12880 KB |
Output is correct |
4 |
Correct |
102 ms |
12924 KB |
Output is correct |
5 |
Correct |
104 ms |
12940 KB |
Output is correct |
6 |
Correct |
109 ms |
12856 KB |
Output is correct |
7 |
Correct |
139 ms |
12888 KB |
Output is correct |
8 |
Correct |
128 ms |
12868 KB |
Output is correct |
9 |
Correct |
135 ms |
12880 KB |
Output is correct |
10 |
Correct |
99 ms |
12880 KB |
Output is correct |
11 |
Correct |
98 ms |
12424 KB |
Output is correct |
12 |
Correct |
98 ms |
12236 KB |
Output is correct |
13 |
Correct |
109 ms |
12444 KB |
Output is correct |
14 |
Correct |
100 ms |
12336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3664 KB |
Output is correct |
2 |
Correct |
28 ms |
4588 KB |
Output is correct |
3 |
Correct |
29 ms |
5652 KB |
Output is correct |
4 |
Correct |
70 ms |
12188 KB |
Output is correct |
5 |
Correct |
89 ms |
12220 KB |
Output is correct |
6 |
Correct |
98 ms |
12584 KB |
Output is correct |
7 |
Correct |
98 ms |
12332 KB |
Output is correct |
8 |
Correct |
68 ms |
11684 KB |
Output is correct |
9 |
Correct |
69 ms |
12260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2512 KB |
Output is correct |
2 |
Correct |
14 ms |
3644 KB |
Output is correct |
3 |
Correct |
63 ms |
11112 KB |
Output is correct |
4 |
Correct |
128 ms |
12868 KB |
Output is correct |
5 |
Correct |
135 ms |
12924 KB |
Output is correct |
6 |
Correct |
102 ms |
12860 KB |
Output is correct |
7 |
Correct |
90 ms |
12944 KB |
Output is correct |
8 |
Correct |
85 ms |
12876 KB |
Output is correct |
9 |
Correct |
112 ms |
12944 KB |
Output is correct |
10 |
Correct |
145 ms |
13004 KB |
Output is correct |
11 |
Correct |
100 ms |
12336 KB |
Output is correct |
12 |
Correct |
102 ms |
12476 KB |
Output is correct |
13 |
Correct |
95 ms |
12276 KB |
Output is correct |
14 |
Correct |
120 ms |
12104 KB |
Output is correct |
15 |
Correct |
86 ms |
12932 KB |
Output is correct |
16 |
Correct |
86 ms |
12960 KB |
Output is correct |
17 |
Correct |
106 ms |
12348 KB |
Output is correct |
18 |
Correct |
102 ms |
12300 KB |
Output is correct |
19 |
Correct |
87 ms |
12948 KB |
Output is correct |
20 |
Correct |
141 ms |
12472 KB |
Output is correct |
21 |
Correct |
77 ms |
14060 KB |
Output is correct |
22 |
Correct |
77 ms |
14104 KB |
Output is correct |
23 |
Correct |
123 ms |
13468 KB |
Output is correct |
24 |
Correct |
109 ms |
13328 KB |
Output is correct |
25 |
Correct |
117 ms |
12380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
3576 KB |
Output is correct |
2 |
Correct |
18 ms |
3752 KB |
Output is correct |
3 |
Correct |
146 ms |
13388 KB |
Output is correct |
4 |
Correct |
169 ms |
13808 KB |
Output is correct |
5 |
Correct |
143 ms |
15452 KB |
Output is correct |
6 |
Correct |
191 ms |
14360 KB |
Output is correct |
7 |
Correct |
148 ms |
14852 KB |
Output is correct |
8 |
Correct |
150 ms |
15112 KB |
Output is correct |
9 |
Incorrect |
142 ms |
10252 KB |
Output is incorrect: {s, t} is wrong. |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
3536 KB |
Output is correct |
2 |
Correct |
18 ms |
3840 KB |
Output is correct |
3 |
Correct |
127 ms |
13364 KB |
Output is correct |
4 |
Correct |
114 ms |
13428 KB |
Output is correct |
5 |
Correct |
136 ms |
13308 KB |
Output is correct |
6 |
Correct |
175 ms |
14600 KB |
Output is correct |
7 |
Correct |
134 ms |
13284 KB |
Output is correct |
8 |
Correct |
185 ms |
13804 KB |
Output is correct |
9 |
Incorrect |
144 ms |
13580 KB |
Output is incorrect: {s, t} is wrong. |
10 |
Halted |
0 ms |
0 KB |
- |