#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long ll;
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
vector<int>adj[N];
int M = U.size();
for (int i = 0; i < M; i++)
{
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
vector<int>tarp;
for (int i = 0; i < M; i++)
tarp.push_back(i);
vector<int>w(M, 1);
ll maxi = ask(w);
while (tarp.size() > 1)
{
vector<int>t1;
vector<int>t2;
for (int i = 0; i < tarp.size(); i++)
{
if (i < tarp.size() / 2)
t1.push_back(tarp[i]);
else
t2.push_back(tarp[i]);
}
fill_n(w.begin(), M, 1);
for (int i : t1)
w[i] = 0;
if (ask(w) < maxi)
tarp = t1;
else
tarp = t2;
}
assert(tarp.size() == 1);
int u = U[tarp[0]];
int v = V[tarp[0]];
int s = u;
int t = v;
for (pair<int, int>ab : {make_pair(u, v), make_pair(v, u)})
{
int a = ab.first;
int b = ab.second;
int d[N];
fill_n(d, N, N + 3);
d[a] = 0;
function<void(int, int)>dfs = [&](int i, int p)
{
for (int j : adj[i])
{
if (j == p || d[j] <= d[i])
continue;
d[j] = d[i] + 1;
dfs(j, i);
}
};
dfs(a, b);
int pa[N];
fill_n(pa, N, -1);
for (int i = 0; i < M; i++)
{
if (d[U[i]] > d[V[i]])
swap(U[i], V[i]);
if (d[V[i]] < N + 3)
{
pa[V[i]] = i;
}
}
fill_n(w.begin(), M, 1);
for (int i = 0; i < N; i++)
{
if (pa[i] != -1)
{
w[pa[i]] = 0;
}
}
int de = (maxi - ask(w)) / (ll(B - A));
vector<int>X;
for (int i = 0; i < N; i++)
if (d[i] == de)
X.push_back(i);
while (X.size() > 1)
{
vector<int>x1;
vector<int>x2;
for (int i = 0; i < X.size(); i++)
{
if (i < X.size() / 2)
x1.push_back(X[i]);
else
x2.push_back(X[i]);
}
fill_n(w.begin(), M, 1);
for (int i : x1)
w[pa[i]] = 0;
if (ask(w) < maxi)
X = x1;
else
X = x2;
}
if (a == u)
s = X[0];
else
t = X[0];
}
answer(s, t);
}/*
int main()
{
}
/**/
Compilation message
highway.cpp:115:1: warning: "/*" within comment [-Wcomment]
/**/
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:23:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < tarp.size(); i++)
~~^~~~~~~~~~~~~
highway.cpp:25:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < tarp.size() / 2)
~~^~~~~~~~~~~~~~~~~
highway.cpp:89:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < X.size(); i++)
~~^~~~~~~~~~
highway.cpp:91:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < X.size() / 2)
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
276 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
248 KB |
Output is correct |
9 |
Correct |
2 ms |
248 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
320 KB |
Output is correct |
12 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
19 ms |
1156 KB |
Output is correct |
3 |
Correct |
198 ms |
8508 KB |
Output is correct |
4 |
Correct |
186 ms |
8608 KB |
Output is correct |
5 |
Correct |
183 ms |
8492 KB |
Output is correct |
6 |
Correct |
204 ms |
8496 KB |
Output is correct |
7 |
Correct |
193 ms |
8500 KB |
Output is correct |
8 |
Correct |
190 ms |
8508 KB |
Output is correct |
9 |
Correct |
177 ms |
8564 KB |
Output is correct |
10 |
Correct |
185 ms |
8532 KB |
Output is correct |
11 |
Correct |
184 ms |
9364 KB |
Output is correct |
12 |
Correct |
187 ms |
10332 KB |
Output is correct |
13 |
Correct |
187 ms |
9792 KB |
Output is correct |
14 |
Correct |
194 ms |
9868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
1856 KB |
Output is correct |
2 |
Correct |
38 ms |
3388 KB |
Output is correct |
3 |
Correct |
55 ms |
4992 KB |
Output is correct |
4 |
Correct |
186 ms |
12344 KB |
Output is correct |
5 |
Correct |
162 ms |
12452 KB |
Output is correct |
6 |
Correct |
171 ms |
13652 KB |
Output is correct |
7 |
Correct |
158 ms |
14696 KB |
Output is correct |
8 |
Correct |
174 ms |
12900 KB |
Output is correct |
9 |
Correct |
156 ms |
13268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
392 KB |
Output is correct |
2 |
Correct |
18 ms |
1280 KB |
Output is correct |
3 |
Correct |
117 ms |
6740 KB |
Output is correct |
4 |
Correct |
179 ms |
8524 KB |
Output is correct |
5 |
Correct |
194 ms |
8500 KB |
Output is correct |
6 |
Correct |
178 ms |
8512 KB |
Output is correct |
7 |
Correct |
196 ms |
8492 KB |
Output is correct |
8 |
Correct |
188 ms |
8480 KB |
Output is correct |
9 |
Correct |
177 ms |
8516 KB |
Output is correct |
10 |
Correct |
184 ms |
8524 KB |
Output is correct |
11 |
Correct |
198 ms |
9508 KB |
Output is correct |
12 |
Correct |
217 ms |
10344 KB |
Output is correct |
13 |
Correct |
196 ms |
10032 KB |
Output is correct |
14 |
Correct |
181 ms |
9884 KB |
Output is correct |
15 |
Correct |
192 ms |
8504 KB |
Output is correct |
16 |
Correct |
170 ms |
8436 KB |
Output is correct |
17 |
Correct |
202 ms |
9628 KB |
Output is correct |
18 |
Correct |
191 ms |
10092 KB |
Output is correct |
19 |
Correct |
174 ms |
8516 KB |
Output is correct |
20 |
Correct |
202 ms |
10680 KB |
Output is correct |
21 |
Correct |
159 ms |
9396 KB |
Output is correct |
22 |
Correct |
175 ms |
9420 KB |
Output is correct |
23 |
Correct |
205 ms |
8980 KB |
Output is correct |
24 |
Correct |
178 ms |
9048 KB |
Output is correct |
25 |
Correct |
210 ms |
14184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
796 ms |
1404 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
804 ms |
1424 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |