#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 10;
typedef pair<int,int> ii;
#define ff first
#define ss second
int n,m;
ll dist,w1,w2,dist2;
vector <ii> adj[maxn];
ii e[maxn];
int d[maxn]; ii par[maxn];
int side[maxn], idx;
int dnc()
{
int l=0; int r=m-1;
while (l<r)
{
int mid=(l+r)/2;
vector <int> dau(m,0);
for (int i=0; i<=mid; i++) dau[i] = 1;
ll temp = ask(dau);
if (temp > dist) r = mid;
else l=mid+1;
}
return r;
}
int trace(int id1, int id2, vector <int> nodes, vector <int> nodes2)
{
int l=0; int r=nodes.size()-1;
while (l<r)
{
int mid = (l+r+1)/2;
vector <int> dau(m,1);
dau[idx] = 0;
for (int i=0; i<mid; i++) if (par[nodes[i]].ff!=-1) dau[par[nodes[i]].ss] = 0;
for (int i:nodes2) if (par[i].ff!=-1) dau[par[i].ss]=0;
if (ask(dau)>dist) l=mid;
else r=mid-1;
}
return nodes[l];
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
m=U.size(); n=N; w1=A; w2=B;
fill_n(side,n,0);
for (int i=0; i<n; i++) par[i]={-1,-1};
cerr<<":>"<<endl;
for (int i=0; i<n; i++) adj[i].clear();
for (int i=0; i<m; i++) e[i].ff=U[i], e[i].ss = V[i], adj[e[i].ff].push_back({e[i].ss,i}), adj[e[i].ss].push_back({e[i].ff,i});
vector <int32_t> dau(m,0);
dist=ask(dau);
cerr<<dist<<endl;
idx = dnc();
cerr<<idx<<endl;
fill_n(d,n,-1);
int u=e[idx].ff; int v=e[idx].ss;
d[u]=d[v]=0; par[u] = par[v] = {-1,-1};
dau[idx] = -1;
queue<int> q;
q.push(u); q.push(v);
side[u] = 1; side[v] = 2;
vector <int> nodes[3];
nodes[1].push_back(u);
nodes[2].push_back(v);
while (!q.empty())
{
int u=q.front(); q.pop();
for (ii i:adj[u])
{
int v=i.ff; int id = i.ss;
if (d[v]==-1)
{
par[v] = {u,id};
side[v] = side[u];
d[v] = d[u]+1;
// cerr<<u<<" - "<<v<<endl;
dau[id] = side[v];
nodes[side[v]].push_back(v);
q.push(v);
}
}
}
answer(trace(1,2,nodes[1],nodes[2]), trace(2,1,nodes[2],nodes[1]));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
4 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5028 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
5024 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
3 ms |
4944 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
5028 KB |
Output is correct |
11 |
Correct |
3 ms |
4944 KB |
Output is correct |
12 |
Correct |
3 ms |
5028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5072 KB |
Output is correct |
2 |
Correct |
16 ms |
5972 KB |
Output is correct |
3 |
Correct |
137 ms |
13736 KB |
Output is correct |
4 |
Correct |
150 ms |
13720 KB |
Output is correct |
5 |
Correct |
145 ms |
13728 KB |
Output is correct |
6 |
Correct |
142 ms |
13368 KB |
Output is correct |
7 |
Correct |
156 ms |
13716 KB |
Output is correct |
8 |
Correct |
154 ms |
13704 KB |
Output is correct |
9 |
Correct |
116 ms |
13732 KB |
Output is correct |
10 |
Correct |
132 ms |
13724 KB |
Output is correct |
11 |
Correct |
171 ms |
13280 KB |
Output is correct |
12 |
Correct |
159 ms |
13260 KB |
Output is correct |
13 |
Correct |
168 ms |
13120 KB |
Output is correct |
14 |
Correct |
176 ms |
13176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5960 KB |
Output is correct |
2 |
Correct |
25 ms |
6852 KB |
Output is correct |
3 |
Correct |
37 ms |
7756 KB |
Output is correct |
4 |
Correct |
112 ms |
13212 KB |
Output is correct |
5 |
Correct |
102 ms |
13216 KB |
Output is correct |
6 |
Correct |
111 ms |
13260 KB |
Output is correct |
7 |
Correct |
109 ms |
13272 KB |
Output is correct |
8 |
Correct |
97 ms |
13156 KB |
Output is correct |
9 |
Correct |
94 ms |
13304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5072 KB |
Output is correct |
2 |
Correct |
14 ms |
5968 KB |
Output is correct |
3 |
Correct |
88 ms |
11716 KB |
Output is correct |
4 |
Correct |
164 ms |
13700 KB |
Output is correct |
5 |
Correct |
143 ms |
13804 KB |
Output is correct |
6 |
Correct |
103 ms |
13380 KB |
Output is correct |
7 |
Correct |
141 ms |
13788 KB |
Output is correct |
8 |
Correct |
107 ms |
13724 KB |
Output is correct |
9 |
Correct |
157 ms |
13728 KB |
Output is correct |
10 |
Correct |
205 ms |
13740 KB |
Output is correct |
11 |
Correct |
151 ms |
13128 KB |
Output is correct |
12 |
Correct |
156 ms |
13212 KB |
Output is correct |
13 |
Correct |
160 ms |
13364 KB |
Output is correct |
14 |
Correct |
163 ms |
13240 KB |
Output is correct |
15 |
Correct |
140 ms |
13624 KB |
Output is correct |
16 |
Correct |
94 ms |
13400 KB |
Output is correct |
17 |
Correct |
173 ms |
13148 KB |
Output is correct |
18 |
Correct |
148 ms |
13212 KB |
Output is correct |
19 |
Correct |
102 ms |
13792 KB |
Output is correct |
20 |
Correct |
147 ms |
13240 KB |
Output is correct |
21 |
Correct |
106 ms |
14028 KB |
Output is correct |
22 |
Correct |
126 ms |
14380 KB |
Output is correct |
23 |
Correct |
153 ms |
14240 KB |
Output is correct |
24 |
Correct |
182 ms |
14180 KB |
Output is correct |
25 |
Correct |
189 ms |
13412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
5968 KB |
Output is correct |
2 |
Correct |
16 ms |
6152 KB |
Output is correct |
3 |
Correct |
177 ms |
14280 KB |
Output is correct |
4 |
Correct |
219 ms |
14964 KB |
Output is correct |
5 |
Correct |
252 ms |
16024 KB |
Output is correct |
6 |
Correct |
211 ms |
16108 KB |
Output is correct |
7 |
Correct |
207 ms |
16228 KB |
Output is correct |
8 |
Correct |
233 ms |
16248 KB |
Output is correct |
9 |
Correct |
162 ms |
12892 KB |
Output is correct |
10 |
Correct |
181 ms |
13352 KB |
Output is correct |
11 |
Correct |
153 ms |
14028 KB |
Output is correct |
12 |
Correct |
222 ms |
15372 KB |
Output is correct |
13 |
Correct |
202 ms |
15880 KB |
Output is correct |
14 |
Correct |
212 ms |
16220 KB |
Output is correct |
15 |
Correct |
230 ms |
15988 KB |
Output is correct |
16 |
Correct |
224 ms |
14132 KB |
Output is correct |
17 |
Correct |
181 ms |
14224 KB |
Output is correct |
18 |
Correct |
175 ms |
14440 KB |
Output is correct |
19 |
Correct |
203 ms |
14356 KB |
Output is correct |
20 |
Correct |
127 ms |
14584 KB |
Output is correct |
21 |
Correct |
203 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
6004 KB |
Output is correct |
2 |
Correct |
25 ms |
6092 KB |
Output is correct |
3 |
Correct |
181 ms |
14428 KB |
Output is correct |
4 |
Correct |
163 ms |
14664 KB |
Output is correct |
5 |
Correct |
182 ms |
14840 KB |
Output is correct |
6 |
Correct |
210 ms |
16004 KB |
Output is correct |
7 |
Correct |
129 ms |
14240 KB |
Output is correct |
8 |
Correct |
157 ms |
14528 KB |
Output is correct |
9 |
Correct |
191 ms |
14884 KB |
Output is correct |
10 |
Correct |
199 ms |
16104 KB |
Output is correct |
11 |
Correct |
202 ms |
16092 KB |
Output is correct |
12 |
Correct |
212 ms |
16300 KB |
Output is correct |
13 |
Correct |
174 ms |
14084 KB |
Output is correct |
14 |
Correct |
185 ms |
13364 KB |
Output is correct |
15 |
Correct |
163 ms |
13988 KB |
Output is correct |
16 |
Correct |
119 ms |
13444 KB |
Output is correct |
17 |
Correct |
203 ms |
14000 KB |
Output is correct |
18 |
Correct |
184 ms |
13432 KB |
Output is correct |
19 |
Correct |
187 ms |
15372 KB |
Output is correct |
20 |
Correct |
240 ms |
15652 KB |
Output is correct |
21 |
Correct |
185 ms |
16320 KB |
Output is correct |
22 |
Correct |
234 ms |
16040 KB |
Output is correct |
23 |
Correct |
181 ms |
16120 KB |
Output is correct |
24 |
Correct |
213 ms |
16264 KB |
Output is correct |
25 |
Correct |
190 ms |
16008 KB |
Output is correct |
26 |
Correct |
238 ms |
16084 KB |
Output is correct |
27 |
Correct |
175 ms |
14484 KB |
Output is correct |
28 |
Correct |
123 ms |
14292 KB |
Output is correct |
29 |
Correct |
113 ms |
14568 KB |
Output is correct |
30 |
Correct |
108 ms |
14432 KB |
Output is correct |
31 |
Correct |
169 ms |
14440 KB |
Output is correct |
32 |
Correct |
143 ms |
14324 KB |
Output is correct |
33 |
Correct |
156 ms |
14528 KB |
Output is correct |
34 |
Correct |
164 ms |
14352 KB |
Output is correct |
35 |
Correct |
115 ms |
14324 KB |
Output is correct |
36 |
Correct |
124 ms |
14224 KB |
Output is correct |
37 |
Correct |
157 ms |
14476 KB |
Output is correct |
38 |
Correct |
110 ms |
14192 KB |
Output is correct |
39 |
Correct |
213 ms |
16080 KB |
Output is correct |
40 |
Correct |
196 ms |
16044 KB |
Output is correct |
41 |
Correct |
225 ms |
15980 KB |
Output is correct |
42 |
Correct |
204 ms |
16076 KB |
Output is correct |