#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[2] = {U[tarp[0]], V[tarp[0]]};
int d[2][N];
int pa[2][N];
for (int t : {0, 1})
{
fill_n(d[t], N, N + 3);
d[t][u[t]] = 0;
queue<int>Q;
Q.push(u[t]);
while (!Q.empty())
{
int a = Q.front();
Q.pop();
for (int b : adj[a])
{
if (d[t][b] > d[t][a] + 1)
{
d[t][b] = d[t][a] + 1;
Q.push(b);
}
}
}
for (int i = 0; i < M; i++)
{
if (d[t][U[i]] < d[t][V[i]])
pa[t][V[i]] = i;
if (d[t][U[i]] > d[t][V[i]])
pa[t][U[i]] = i;
}
pa[t][u[t]] = u[t];
}
ll d_st = maxi / ll(B);
vector<int>v[2];
for (int t : {0, 1})
{
for (int i = 0; i < N; i++)
{
if (d[t][i] < d[1 - t][i])
v[t].push_back(i);
}
}
fill_n(w.begin(), M, 1);
if (v[0].size() > 1)
for (int i : v[0])
w[pa[0][i]] = 0;
int d_s = ((maxi - ask(w)) / ll(B - A));
int d_t = d_st - d_s - 1;
vector<int>s, t;
for (int i : v[0])
if (d[0][i] == d_s)
s.push_back(i);
for (int i : v[1])
if (d[1][i] == d_t)
t.push_back(i);
while (s.size() > 1)
{
vector<int>s1, s2;
for (int i = 0; i < s.size(); i++)
{
if (i < s.size() / 2)
s1.push_back(s[i]);
else
s2.push_back(s[i]);
}
fill_n(w.begin(), M, 1ll);
for (int i : s1)
w[pa[0][i]] = 0;
if (ask(w) < maxi)
s = s1;
else
s = s2;
}
while (t.size() > 1)
{
vector<int>t1, t2;
for (int i = 0; i < t.size(); i++)
{
if (i < t.size() / 2)
t1.push_back(t[i]);
else
t2.push_back(t[i]);
}
fill_n(w.begin(), M, 1ll);
for (int i : t1)
w[pa[1][i]] = 0;
if (ask(w) < maxi)
t = t1;
else
t = t2;
}
answer(s[0], t[0]);
}/*
int main()
{
}
/**/
Compilation message
highway.cpp:135: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:96:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++)
~~^~~~~~~~~~
highway.cpp:98:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < s.size() / 2)
~~^~~~~~~~~~~~~~
highway.cpp:114:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < t.size(); i++)
~~^~~~~~~~~~
highway.cpp:116:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < t.size() / 2)
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
320 KB |
Output is correct |
5 |
Correct |
2 ms |
320 KB |
Output is correct |
6 |
Incorrect |
2 ms |
248 KB |
Output is incorrect: {s, t} is wrong. |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
400 KB |
Output is correct |
2 |
Correct |
27 ms |
1384 KB |
Output is correct |
3 |
Correct |
207 ms |
9568 KB |
Output is correct |
4 |
Correct |
196 ms |
9588 KB |
Output is correct |
5 |
Correct |
190 ms |
9648 KB |
Output is correct |
6 |
Correct |
197 ms |
9636 KB |
Output is correct |
7 |
Correct |
185 ms |
9584 KB |
Output is correct |
8 |
Correct |
179 ms |
9548 KB |
Output is correct |
9 |
Correct |
193 ms |
9596 KB |
Output is correct |
10 |
Correct |
179 ms |
9596 KB |
Output is correct |
11 |
Correct |
208 ms |
9336 KB |
Output is correct |
12 |
Correct |
210 ms |
9488 KB |
Output is correct |
13 |
Correct |
237 ms |
9492 KB |
Output is correct |
14 |
Correct |
211 ms |
9484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
1400 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
23 ms |
1260 KB |
Output is correct |
3 |
Correct |
140 ms |
7644 KB |
Output is correct |
4 |
Correct |
196 ms |
9548 KB |
Output is correct |
5 |
Correct |
190 ms |
9596 KB |
Output is correct |
6 |
Correct |
203 ms |
9664 KB |
Output is correct |
7 |
Correct |
205 ms |
9712 KB |
Output is correct |
8 |
Correct |
163 ms |
9748 KB |
Output is correct |
9 |
Correct |
199 ms |
9572 KB |
Output is correct |
10 |
Correct |
196 ms |
9588 KB |
Output is correct |
11 |
Correct |
191 ms |
9472 KB |
Output is correct |
12 |
Correct |
210 ms |
9600 KB |
Output is correct |
13 |
Correct |
239 ms |
9488 KB |
Output is correct |
14 |
Correct |
192 ms |
9280 KB |
Output is correct |
15 |
Correct |
182 ms |
9600 KB |
Output is correct |
16 |
Correct |
176 ms |
9576 KB |
Output is correct |
17 |
Correct |
182 ms |
9556 KB |
Output is correct |
18 |
Correct |
207 ms |
9524 KB |
Output is correct |
19 |
Correct |
211 ms |
9580 KB |
Output is correct |
20 |
Correct |
209 ms |
9528 KB |
Output is correct |
21 |
Correct |
174 ms |
10444 KB |
Output is correct |
22 |
Correct |
173 ms |
10456 KB |
Output is correct |
23 |
Correct |
198 ms |
10280 KB |
Output is correct |
24 |
Correct |
188 ms |
10148 KB |
Output is correct |
25 |
Correct |
213 ms |
9528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
1344 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1424 KB |
Output is correct |
2 |
Correct |
46 ms |
1384 KB |
Output is correct |
3 |
Correct |
208 ms |
9768 KB |
Output is correct |
4 |
Correct |
235 ms |
9952 KB |
Output is correct |
5 |
Incorrect |
252 ms |
10156 KB |
Output is incorrect: {s, t} is wrong. |
6 |
Halted |
0 ms |
0 KB |
- |