#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int n = N, M = U.size();
vector <vector<ar<int,2>>> adj(n);
for ( int i = 0; i < M; i++ ){
adj[U[i]].pb({V[i], i});
adj[V[i]].pb({U[i], i});
}
vector <int> w(M);
i64 C = ask(w);
int l = 0, r = n - 1, ans;
while ( l <= r ){
int m = (l + r) / 2;
if ( r - l > 60000 ) m = 60000;
w.assign(M, 0);
for ( int u = m + 1; u < n; u++ ){
for ( auto &[v, j]: adj[u] ){
w[j] = 1;
}
}
if ( ask(w) == C ){
ans = m;
r = m - 1;
} else l = m + 1;
}
int root = ans;
vector <int> fa(n), ls, us(n);
queue <int> q;
q.push(root); us[root] = 1;
while ( !q.empty() ){
int u = q.front();
q.pop();
ls.pb(u);
for ( auto &[v, j]: adj[u] ){
if ( us[v] ) continue;
us[v] = 1;
fa[v] = u;
q.push(v);
}
}
vector <int> e(n, -1);
for ( int u = 0; u < n; u++ ){
for ( auto &[v, j]: adj[u] ){
if ( fa[u] == v ){
e[u] = j;
}
}
}
l = 1, r = n - 1;
while ( l <= r ){
int m = (l + r) / 2;
w.assign(M, 1);
for ( int i = 1; i <= m; i++ ){
w[e[ls[i]]] = 0;
}
if ( ask(w) == C ){
ans = m;
r = m - 1;
} else l = m + 1;
}
int sx = ls[ans];
vector <int> pth;
{ // path from sx to root
int it = sx;
while ( it != root ){
pth.pb(e[it]);
it = fa[it];
}
}
l = 0, r = ans - 1;
while ( l <= r ){
int m = (l + r) / 2;
w.assign(M, 1);
for ( auto &j: pth ) w[j] = 0;
for ( int i = 0; i < m; i++ ){
w[e[ls[i + 1]]] = 0;
}
if ( ask(w) == C ){
ans = m;
r = m - 1;
} else l = m + 1;
}
int se = ls[ans];
answer(sx, se);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:125:18: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
125 | while ( it != root ){
| ~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
1444 KB |
Output is correct |
3 |
Correct |
79 ms |
9268 KB |
Output is correct |
4 |
Correct |
96 ms |
9280 KB |
Output is correct |
5 |
Correct |
80 ms |
9276 KB |
Output is correct |
6 |
Correct |
78 ms |
9564 KB |
Output is correct |
7 |
Correct |
69 ms |
9264 KB |
Output is correct |
8 |
Correct |
77 ms |
9268 KB |
Output is correct |
9 |
Correct |
71 ms |
9508 KB |
Output is correct |
10 |
Correct |
85 ms |
9400 KB |
Output is correct |
11 |
Correct |
88 ms |
8664 KB |
Output is correct |
12 |
Correct |
97 ms |
9124 KB |
Output is correct |
13 |
Correct |
92 ms |
8664 KB |
Output is correct |
14 |
Correct |
84 ms |
8664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1472 KB |
Output is correct |
2 |
Correct |
15 ms |
2276 KB |
Output is correct |
3 |
Correct |
22 ms |
2968 KB |
Output is correct |
4 |
Correct |
68 ms |
8740 KB |
Output is correct |
5 |
Correct |
56 ms |
8668 KB |
Output is correct |
6 |
Correct |
72 ms |
9148 KB |
Output is correct |
7 |
Correct |
56 ms |
8664 KB |
Output is correct |
8 |
Correct |
68 ms |
8896 KB |
Output is correct |
9 |
Correct |
64 ms |
8664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
9 ms |
1448 KB |
Output is correct |
3 |
Correct |
63 ms |
7348 KB |
Output is correct |
4 |
Correct |
70 ms |
9256 KB |
Output is correct |
5 |
Correct |
69 ms |
9260 KB |
Output is correct |
6 |
Correct |
74 ms |
9256 KB |
Output is correct |
7 |
Correct |
84 ms |
9460 KB |
Output is correct |
8 |
Correct |
67 ms |
9240 KB |
Output is correct |
9 |
Correct |
80 ms |
9488 KB |
Output is correct |
10 |
Correct |
82 ms |
9268 KB |
Output is correct |
11 |
Correct |
100 ms |
8668 KB |
Output is correct |
12 |
Correct |
88 ms |
8976 KB |
Output is correct |
13 |
Correct |
85 ms |
8672 KB |
Output is correct |
14 |
Correct |
76 ms |
8660 KB |
Output is correct |
15 |
Correct |
68 ms |
9268 KB |
Output is correct |
16 |
Correct |
75 ms |
9272 KB |
Output is correct |
17 |
Correct |
72 ms |
8660 KB |
Output is correct |
18 |
Correct |
82 ms |
8676 KB |
Output is correct |
19 |
Correct |
70 ms |
9280 KB |
Output is correct |
20 |
Correct |
74 ms |
8668 KB |
Output is correct |
21 |
Correct |
71 ms |
10272 KB |
Output is correct |
22 |
Correct |
86 ms |
9900 KB |
Output is correct |
23 |
Correct |
86 ms |
9548 KB |
Output is correct |
24 |
Correct |
78 ms |
9948 KB |
Output is correct |
25 |
Correct |
76 ms |
9080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1368 KB |
Output is correct |
2 |
Correct |
9 ms |
1368 KB |
Output is correct |
3 |
Correct |
89 ms |
10256 KB |
Output is correct |
4 |
Correct |
95 ms |
10092 KB |
Output is correct |
5 |
Correct |
105 ms |
11120 KB |
Output is correct |
6 |
Correct |
117 ms |
11072 KB |
Output is correct |
7 |
Correct |
125 ms |
11076 KB |
Output is correct |
8 |
Correct |
128 ms |
11236 KB |
Output is correct |
9 |
Correct |
99 ms |
7360 KB |
Output is correct |
10 |
Correct |
91 ms |
7532 KB |
Output is correct |
11 |
Correct |
100 ms |
8324 KB |
Output is correct |
12 |
Correct |
101 ms |
10032 KB |
Output is correct |
13 |
Correct |
126 ms |
10892 KB |
Output is correct |
14 |
Correct |
126 ms |
11208 KB |
Output is correct |
15 |
Correct |
117 ms |
11060 KB |
Output is correct |
16 |
Correct |
95 ms |
8760 KB |
Output is correct |
17 |
Correct |
96 ms |
10260 KB |
Output is correct |
18 |
Correct |
81 ms |
10208 KB |
Output is correct |
19 |
Correct |
84 ms |
9876 KB |
Output is correct |
20 |
Correct |
73 ms |
10036 KB |
Output is correct |
21 |
Correct |
100 ms |
11228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1368 KB |
Output is correct |
2 |
Correct |
14 ms |
1524 KB |
Output is correct |
3 |
Correct |
91 ms |
9696 KB |
Output is correct |
4 |
Correct |
101 ms |
9864 KB |
Output is correct |
5 |
Correct |
104 ms |
10172 KB |
Output is correct |
6 |
Correct |
127 ms |
11248 KB |
Output is correct |
7 |
Correct |
95 ms |
9676 KB |
Output is correct |
8 |
Correct |
97 ms |
9780 KB |
Output is correct |
9 |
Correct |
82 ms |
10112 KB |
Output is correct |
10 |
Correct |
140 ms |
11096 KB |
Output is correct |
11 |
Correct |
121 ms |
11292 KB |
Output is correct |
12 |
Correct |
118 ms |
11080 KB |
Output is correct |
13 |
Correct |
98 ms |
8344 KB |
Output is correct |
14 |
Correct |
98 ms |
7520 KB |
Output is correct |
15 |
Correct |
79 ms |
8356 KB |
Output is correct |
16 |
Correct |
87 ms |
7616 KB |
Output is correct |
17 |
Correct |
101 ms |
8520 KB |
Output is correct |
18 |
Correct |
82 ms |
7572 KB |
Output is correct |
19 |
Correct |
126 ms |
10240 KB |
Output is correct |
20 |
Correct |
97 ms |
10512 KB |
Output is correct |
21 |
Correct |
100 ms |
11104 KB |
Output is correct |
22 |
Correct |
116 ms |
11120 KB |
Output is correct |
23 |
Correct |
120 ms |
11056 KB |
Output is correct |
24 |
Correct |
100 ms |
11216 KB |
Output is correct |
25 |
Correct |
102 ms |
11064 KB |
Output is correct |
26 |
Correct |
106 ms |
11076 KB |
Output is correct |
27 |
Correct |
80 ms |
10128 KB |
Output is correct |
28 |
Correct |
87 ms |
9876 KB |
Output is correct |
29 |
Correct |
78 ms |
10104 KB |
Output is correct |
30 |
Correct |
74 ms |
9860 KB |
Output is correct |
31 |
Correct |
87 ms |
9928 KB |
Output is correct |
32 |
Correct |
76 ms |
9856 KB |
Output is correct |
33 |
Correct |
89 ms |
10696 KB |
Output is correct |
34 |
Correct |
84 ms |
9872 KB |
Output is correct |
35 |
Correct |
61 ms |
9956 KB |
Output is correct |
36 |
Correct |
73 ms |
10296 KB |
Output is correct |
37 |
Correct |
68 ms |
10036 KB |
Output is correct |
38 |
Correct |
109 ms |
9952 KB |
Output is correct |
39 |
Correct |
119 ms |
11052 KB |
Output is correct |
40 |
Correct |
95 ms |
11028 KB |
Output is correct |
41 |
Partially correct |
130 ms |
11008 KB |
Output is partially correct |
42 |
Correct |
113 ms |
11032 KB |
Output is correct |