#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> p2;
typedef tuple<int,int,int> t3;
const int N=90005;
const int M=130005;
int n,m,a,b;
vector<int> e;
vector<int> edge1(M),edge2(M),dist1(N),dist2(N);
vector<p2> adj[N];
long long cost;
vector<t3> group1,group2;
int type[M];
int mainedge;
void bfs(int st,vector<int> &dist,vector<int> &edge){
queue<int> q;
edge[st]=mainedge;
dist[st]=1;
q.emplace(st);
while(!q.empty()){
auto u=q.front();
q.pop();
for(auto [v,id]:adj[u]){
if(dist[v])continue;
edge[v]=id;
dist[v]=dist[u]+1;
q.emplace(v);
}
}
}
int sol1(){
int l=0,r=m-1;
while(l<r){
int mid=(l+r)/2;
for(int i=0;i<m;i++)e[i]=i<=mid;
if(ask(e)!=cost)r=mid;
else l=mid+1;
}
return l;
}
int sol2(vector<t3> &ingroup,vector<t3> &exgroup){
int l=0,r=ingroup.size()-1;
while(l<r){
int mid=(l+r)/2;
e=vector<int>(m,1);
for(auto x:exgroup)e[get<2>(x)]=0;
for(int i=1;i<=mid;i++)e[get<2>(ingroup[i])]=0;
if(ask(e)==cost)r=mid;
else l=mid+1;
}
return get<1>(ingroup[l]);
}
void find_pair(int n, vector<int> U, vector<int> V, int A, int B){
a=A,b=B;
m=U.size();
for(int i=0;i<m;i++){
int u=U[i],v=V[i];
adj[u].emplace_back(v,i);
adj[v].emplace_back(u,i);
}
e=vector<int>(m,0);
cost=ask(e);
mainedge=sol1();
int st1=U[mainedge];
int st2=V[mainedge];
bfs(st1,dist1,edge1);
bfs(st2,dist2,edge2);
for(int i=0;i<n;i++){
if(dist1[i]<dist2[i])group1.emplace_back(dist1[i],i,edge1[i]);
if(dist2[i]<dist1[i])group2.emplace_back(dist2[i],i,edge2[i]);
}
sort(group1.begin(),group1.end());
sort(group2.begin(),group2.end());
int ans1=sol2(group1,group2);
int ans2=sol2(group2,group1);
answer(ans1,ans2);
}
Compilation message
highway.cpp: In function 'void bfs(int, std::vector<int>&, std::vector<int>&)':
highway.cpp:29:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | for(auto [v,id]:adj[u]){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4048 KB |
Output is correct |
2 |
Correct |
2 ms |
4048 KB |
Output is correct |
3 |
Correct |
2 ms |
4160 KB |
Output is correct |
4 |
Correct |
2 ms |
4048 KB |
Output is correct |
5 |
Correct |
2 ms |
4048 KB |
Output is correct |
6 |
Correct |
2 ms |
4176 KB |
Output is correct |
7 |
Correct |
2 ms |
4164 KB |
Output is correct |
8 |
Correct |
2 ms |
4048 KB |
Output is correct |
9 |
Correct |
2 ms |
4048 KB |
Output is correct |
10 |
Correct |
2 ms |
4100 KB |
Output is correct |
11 |
Correct |
2 ms |
4048 KB |
Output is correct |
12 |
Correct |
2 ms |
4048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4304 KB |
Output is correct |
2 |
Correct |
10 ms |
4992 KB |
Output is correct |
3 |
Correct |
97 ms |
10940 KB |
Output is correct |
4 |
Correct |
92 ms |
10944 KB |
Output is correct |
5 |
Correct |
88 ms |
10956 KB |
Output is correct |
6 |
Correct |
82 ms |
10972 KB |
Output is correct |
7 |
Correct |
98 ms |
10932 KB |
Output is correct |
8 |
Correct |
88 ms |
10912 KB |
Output is correct |
9 |
Correct |
87 ms |
10968 KB |
Output is correct |
10 |
Correct |
96 ms |
10936 KB |
Output is correct |
11 |
Correct |
96 ms |
10144 KB |
Output is correct |
12 |
Correct |
93 ms |
10764 KB |
Output is correct |
13 |
Correct |
100 ms |
10336 KB |
Output is correct |
14 |
Correct |
92 ms |
10404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4944 KB |
Output is correct |
2 |
Correct |
17 ms |
5596 KB |
Output is correct |
3 |
Correct |
25 ms |
6184 KB |
Output is correct |
4 |
Correct |
69 ms |
10264 KB |
Output is correct |
5 |
Correct |
76 ms |
10264 KB |
Output is correct |
6 |
Correct |
68 ms |
10528 KB |
Output is correct |
7 |
Correct |
72 ms |
10348 KB |
Output is correct |
8 |
Correct |
63 ms |
10140 KB |
Output is correct |
9 |
Correct |
72 ms |
10336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4176 KB |
Output is correct |
2 |
Correct |
11 ms |
4944 KB |
Output is correct |
3 |
Correct |
97 ms |
9804 KB |
Output is correct |
4 |
Correct |
90 ms |
10920 KB |
Output is correct |
5 |
Correct |
83 ms |
10876 KB |
Output is correct |
6 |
Correct |
86 ms |
10992 KB |
Output is correct |
7 |
Correct |
93 ms |
10988 KB |
Output is correct |
8 |
Correct |
84 ms |
10956 KB |
Output is correct |
9 |
Correct |
97 ms |
10944 KB |
Output is correct |
10 |
Correct |
90 ms |
10952 KB |
Output is correct |
11 |
Correct |
104 ms |
10324 KB |
Output is correct |
12 |
Correct |
110 ms |
10500 KB |
Output is correct |
13 |
Correct |
133 ms |
10824 KB |
Output is correct |
14 |
Correct |
109 ms |
10144 KB |
Output is correct |
15 |
Correct |
80 ms |
10892 KB |
Output is correct |
16 |
Correct |
92 ms |
10904 KB |
Output is correct |
17 |
Correct |
97 ms |
10408 KB |
Output is correct |
18 |
Correct |
114 ms |
10336 KB |
Output is correct |
19 |
Correct |
94 ms |
10872 KB |
Output is correct |
20 |
Correct |
102 ms |
10376 KB |
Output is correct |
21 |
Correct |
75 ms |
11632 KB |
Output is correct |
22 |
Correct |
111 ms |
11732 KB |
Output is correct |
23 |
Correct |
91 ms |
11200 KB |
Output is correct |
24 |
Correct |
90 ms |
10960 KB |
Output is correct |
25 |
Correct |
88 ms |
10492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
4944 KB |
Output is correct |
2 |
Correct |
14 ms |
5064 KB |
Output is correct |
3 |
Correct |
105 ms |
11296 KB |
Output is correct |
4 |
Correct |
121 ms |
11836 KB |
Output is correct |
5 |
Correct |
132 ms |
12744 KB |
Output is correct |
6 |
Correct |
150 ms |
12644 KB |
Output is correct |
7 |
Correct |
129 ms |
12772 KB |
Output is correct |
8 |
Correct |
132 ms |
12496 KB |
Output is correct |
9 |
Correct |
113 ms |
10512 KB |
Output is correct |
10 |
Correct |
90 ms |
10956 KB |
Output is correct |
11 |
Correct |
111 ms |
11472 KB |
Output is correct |
12 |
Correct |
124 ms |
12056 KB |
Output is correct |
13 |
Correct |
140 ms |
12368 KB |
Output is correct |
14 |
Correct |
128 ms |
12576 KB |
Output is correct |
15 |
Correct |
145 ms |
12684 KB |
Output is correct |
16 |
Correct |
117 ms |
11464 KB |
Output is correct |
17 |
Correct |
83 ms |
11204 KB |
Output is correct |
18 |
Correct |
85 ms |
11440 KB |
Output is correct |
19 |
Correct |
83 ms |
11260 KB |
Output is correct |
20 |
Correct |
88 ms |
11324 KB |
Output is correct |
21 |
Correct |
144 ms |
12976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
4944 KB |
Output is correct |
2 |
Correct |
14 ms |
5132 KB |
Output is correct |
3 |
Correct |
109 ms |
11036 KB |
Output is correct |
4 |
Correct |
123 ms |
11568 KB |
Output is correct |
5 |
Correct |
133 ms |
11652 KB |
Output is correct |
6 |
Correct |
137 ms |
12660 KB |
Output is correct |
7 |
Correct |
104 ms |
11336 KB |
Output is correct |
8 |
Correct |
111 ms |
11488 KB |
Output is correct |
9 |
Correct |
117 ms |
11404 KB |
Output is correct |
10 |
Correct |
130 ms |
12504 KB |
Output is correct |
11 |
Correct |
131 ms |
12712 KB |
Output is correct |
12 |
Correct |
128 ms |
12524 KB |
Output is correct |
13 |
Correct |
105 ms |
11408 KB |
Output is correct |
14 |
Correct |
87 ms |
10904 KB |
Output is correct |
15 |
Correct |
105 ms |
11456 KB |
Output is correct |
16 |
Correct |
96 ms |
10964 KB |
Output is correct |
17 |
Correct |
108 ms |
11360 KB |
Output is correct |
18 |
Correct |
90 ms |
11000 KB |
Output is correct |
19 |
Correct |
119 ms |
12000 KB |
Output is correct |
20 |
Correct |
133 ms |
12496 KB |
Output is correct |
21 |
Correct |
128 ms |
12752 KB |
Output is correct |
22 |
Correct |
137 ms |
12548 KB |
Output is correct |
23 |
Correct |
136 ms |
12460 KB |
Output is correct |
24 |
Correct |
138 ms |
12544 KB |
Output is correct |
25 |
Correct |
139 ms |
12844 KB |
Output is correct |
26 |
Correct |
145 ms |
12852 KB |
Output is correct |
27 |
Correct |
94 ms |
11288 KB |
Output is correct |
28 |
Correct |
84 ms |
11204 KB |
Output is correct |
29 |
Correct |
82 ms |
11460 KB |
Output is correct |
30 |
Correct |
99 ms |
11232 KB |
Output is correct |
31 |
Correct |
90 ms |
11196 KB |
Output is correct |
32 |
Correct |
87 ms |
11212 KB |
Output is correct |
33 |
Correct |
79 ms |
11376 KB |
Output is correct |
34 |
Correct |
83 ms |
11204 KB |
Output is correct |
35 |
Correct |
82 ms |
11276 KB |
Output is correct |
36 |
Correct |
90 ms |
11080 KB |
Output is correct |
37 |
Correct |
125 ms |
11328 KB |
Output is correct |
38 |
Correct |
90 ms |
11344 KB |
Output is correct |
39 |
Correct |
156 ms |
13068 KB |
Output is correct |
40 |
Correct |
150 ms |
12880 KB |
Output is correct |
41 |
Correct |
123 ms |
12672 KB |
Output is correct |
42 |
Correct |
149 ms |
12712 KB |
Output is correct |