#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
ll n, m, d[NMAX], cost;
vector<pair<int, int>> adj[NMAX];
vector<int> A[2];
/*
ll ask(vector<int> w){
cout << "query : ";
for(int i = 0; i < m; i++) cout << w[i] << ' ';
cout << endl;
ll x;
cin >> x;
return x;
}
void answer(int s, int t){
cout << s << ' ' << t << '\n';
return;
}
*/
void find_pair(int n_, vector<int> U, std::vector<int> V, int a, int b) {
n = n_; m = U.size();
for(int i = 0; i < m; i++){
adj[U[i]].emplace_back(V[i], i);
adj[V[i]].emplace_back(U[i], i);
}
cost = ask(vector<int>(m));
int l = 0, r = m - 1, mid;
while(l < r){
mid = (l + r) / 2;
vector<int> w(m);
fill(w.begin(), w.begin() + mid + 1, 1);
if(ask(w) > cost) r = mid;
else l = mid + 1;
}
int u[2] = {U[l], V[l]};
memset(d, 0x3f, sizeof(d));
d[u[0]] = d[u[1]] = 1;
queue<pair<int, int>> q;
q.emplace(u[0], 0); q.emplace(u[1], 1);
while(q.size()){
auto[x, p] = q.front(); q.pop();
A[p].emplace_back(x);
for(auto&[nx, e] : adj[x])
if(d[x] + 1 < d[nx]){
d[nx] = d[x] + 1;
q.emplace(nx, p);
}
}
int v[2];
for(int t = 0; t < 2; t++){
int l = 0, r = A[t].size() - 1, mid;
while(l < r){
mid = (l + r) / 2;
vector<int> w(m);
for(int i = mid + 1; i <= r; i++)
for(auto&[j, e] : adj[A[t][i]]) w[e] = 1;
if(ask(w) > cost) l = mid + 1;
else r = mid;
}
v[t] = A[t][l];
}
answer(v[0], v[1]);
return;
}
/*
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, a, b, s, t;
cin >> n >> m >> a >> b >> s >> t;
vector<int> U(m), V(m);
for(int i = 0; i < m; i++) cin >> U[i] >> V[i];
find_pair(n, U, V, a, b);
return 0;
}
*/
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:51:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
51 | auto[x, p] = q.front(); q.pop();
| ^
highway.cpp:53:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
53 | for(auto&[nx, e] : adj[x])
| ^
highway.cpp:66:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for(auto&[j, e] : adj[A[t][i]]) w[e] = 1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3408 KB |
Output is correct |
2 |
Correct |
2 ms |
3408 KB |
Output is correct |
3 |
Correct |
2 ms |
3432 KB |
Output is correct |
4 |
Correct |
2 ms |
3408 KB |
Output is correct |
5 |
Correct |
2 ms |
3408 KB |
Output is correct |
6 |
Correct |
2 ms |
3408 KB |
Output is correct |
7 |
Correct |
2 ms |
3432 KB |
Output is correct |
8 |
Correct |
3 ms |
3584 KB |
Output is correct |
9 |
Correct |
2 ms |
3408 KB |
Output is correct |
10 |
Correct |
2 ms |
3432 KB |
Output is correct |
11 |
Correct |
2 ms |
3408 KB |
Output is correct |
12 |
Correct |
2 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3408 KB |
Output is correct |
2 |
Correct |
11 ms |
4060 KB |
Output is correct |
3 |
Correct |
107 ms |
9084 KB |
Output is correct |
4 |
Correct |
84 ms |
9100 KB |
Output is correct |
5 |
Correct |
72 ms |
9112 KB |
Output is correct |
6 |
Correct |
75 ms |
9108 KB |
Output is correct |
7 |
Correct |
101 ms |
9108 KB |
Output is correct |
8 |
Correct |
115 ms |
9096 KB |
Output is correct |
9 |
Correct |
78 ms |
9088 KB |
Output is correct |
10 |
Correct |
105 ms |
9064 KB |
Output is correct |
11 |
Correct |
90 ms |
8664 KB |
Output is correct |
12 |
Correct |
100 ms |
8556 KB |
Output is correct |
13 |
Correct |
73 ms |
8540 KB |
Output is correct |
14 |
Correct |
81 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
3944 KB |
Output is correct |
2 |
Correct |
16 ms |
4560 KB |
Output is correct |
3 |
Correct |
22 ms |
5228 KB |
Output is correct |
4 |
Correct |
55 ms |
8716 KB |
Output is correct |
5 |
Correct |
124 ms |
8644 KB |
Output is correct |
6 |
Correct |
62 ms |
8640 KB |
Output is correct |
7 |
Correct |
71 ms |
8532 KB |
Output is correct |
8 |
Correct |
73 ms |
8608 KB |
Output is correct |
9 |
Correct |
84 ms |
8524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3480 KB |
Output is correct |
2 |
Correct |
12 ms |
4112 KB |
Output is correct |
3 |
Correct |
70 ms |
7904 KB |
Output is correct |
4 |
Correct |
96 ms |
9092 KB |
Output is correct |
5 |
Correct |
95 ms |
9064 KB |
Output is correct |
6 |
Correct |
115 ms |
9072 KB |
Output is correct |
7 |
Correct |
102 ms |
9088 KB |
Output is correct |
8 |
Correct |
109 ms |
9080 KB |
Output is correct |
9 |
Correct |
80 ms |
9140 KB |
Output is correct |
10 |
Correct |
99 ms |
9108 KB |
Output is correct |
11 |
Correct |
92 ms |
8532 KB |
Output is correct |
12 |
Correct |
95 ms |
8564 KB |
Output is correct |
13 |
Correct |
106 ms |
8640 KB |
Output is correct |
14 |
Correct |
74 ms |
8604 KB |
Output is correct |
15 |
Correct |
93 ms |
9180 KB |
Output is correct |
16 |
Correct |
105 ms |
9100 KB |
Output is correct |
17 |
Correct |
99 ms |
8536 KB |
Output is correct |
18 |
Correct |
75 ms |
8540 KB |
Output is correct |
19 |
Correct |
71 ms |
9096 KB |
Output is correct |
20 |
Correct |
64 ms |
8500 KB |
Output is correct |
21 |
Correct |
105 ms |
10000 KB |
Output is correct |
22 |
Correct |
73 ms |
9988 KB |
Output is correct |
23 |
Correct |
67 ms |
9684 KB |
Output is correct |
24 |
Correct |
75 ms |
9604 KB |
Output is correct |
25 |
Correct |
81 ms |
8688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
4220 KB |
Output is correct |
2 |
Correct |
14 ms |
4188 KB |
Output is correct |
3 |
Correct |
91 ms |
9456 KB |
Output is correct |
4 |
Correct |
96 ms |
9996 KB |
Output is correct |
5 |
Correct |
155 ms |
11000 KB |
Output is correct |
6 |
Correct |
100 ms |
11156 KB |
Output is correct |
7 |
Correct |
159 ms |
11260 KB |
Output is correct |
8 |
Correct |
103 ms |
11276 KB |
Output is correct |
9 |
Correct |
88 ms |
9364 KB |
Output is correct |
10 |
Correct |
98 ms |
9816 KB |
Output is correct |
11 |
Correct |
116 ms |
10212 KB |
Output is correct |
12 |
Correct |
145 ms |
10896 KB |
Output is correct |
13 |
Correct |
147 ms |
11176 KB |
Output is correct |
14 |
Correct |
148 ms |
11268 KB |
Output is correct |
15 |
Correct |
105 ms |
10884 KB |
Output is correct |
16 |
Correct |
130 ms |
10328 KB |
Output is correct |
17 |
Correct |
105 ms |
10012 KB |
Output is correct |
18 |
Correct |
73 ms |
10204 KB |
Output is correct |
19 |
Correct |
78 ms |
10088 KB |
Output is correct |
20 |
Correct |
71 ms |
10176 KB |
Output is correct |
21 |
Correct |
114 ms |
10748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
4068 KB |
Output is correct |
2 |
Correct |
12 ms |
4184 KB |
Output is correct |
3 |
Correct |
100 ms |
9684 KB |
Output is correct |
4 |
Correct |
140 ms |
9944 KB |
Output is correct |
5 |
Correct |
90 ms |
10064 KB |
Output is correct |
6 |
Correct |
133 ms |
11132 KB |
Output is correct |
7 |
Correct |
79 ms |
9468 KB |
Output is correct |
8 |
Correct |
120 ms |
9692 KB |
Output is correct |
9 |
Correct |
115 ms |
10164 KB |
Output is correct |
10 |
Correct |
140 ms |
11264 KB |
Output is correct |
11 |
Correct |
101 ms |
11148 KB |
Output is correct |
12 |
Correct |
132 ms |
11152 KB |
Output is correct |
13 |
Correct |
119 ms |
10160 KB |
Output is correct |
14 |
Correct |
85 ms |
9840 KB |
Output is correct |
15 |
Correct |
132 ms |
10152 KB |
Output is correct |
16 |
Correct |
89 ms |
9824 KB |
Output is correct |
17 |
Correct |
120 ms |
10148 KB |
Output is correct |
18 |
Correct |
90 ms |
9900 KB |
Output is correct |
19 |
Correct |
154 ms |
10872 KB |
Output is correct |
20 |
Correct |
114 ms |
10804 KB |
Output is correct |
21 |
Correct |
108 ms |
11284 KB |
Output is correct |
22 |
Correct |
132 ms |
11264 KB |
Output is correct |
23 |
Correct |
117 ms |
11244 KB |
Output is correct |
24 |
Correct |
113 ms |
11276 KB |
Output is correct |
25 |
Correct |
113 ms |
11296 KB |
Output is correct |
26 |
Correct |
155 ms |
11296 KB |
Output is correct |
27 |
Correct |
65 ms |
10168 KB |
Output is correct |
28 |
Correct |
69 ms |
10020 KB |
Output is correct |
29 |
Correct |
78 ms |
10308 KB |
Output is correct |
30 |
Correct |
107 ms |
10056 KB |
Output is correct |
31 |
Correct |
97 ms |
10092 KB |
Output is correct |
32 |
Correct |
103 ms |
10000 KB |
Output is correct |
33 |
Correct |
96 ms |
10248 KB |
Output is correct |
34 |
Correct |
70 ms |
10084 KB |
Output is correct |
35 |
Correct |
100 ms |
10068 KB |
Output is correct |
36 |
Correct |
64 ms |
9980 KB |
Output is correct |
37 |
Correct |
87 ms |
10172 KB |
Output is correct |
38 |
Correct |
89 ms |
10032 KB |
Output is correct |
39 |
Correct |
102 ms |
10976 KB |
Output is correct |
40 |
Correct |
144 ms |
10916 KB |
Output is correct |
41 |
Correct |
130 ms |
10792 KB |
Output is correct |
42 |
Correct |
139 ms |
11072 KB |
Output is correct |