#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long ll;
vector<vector<pair<int, int>>> adj;
vector<int> city;
vector<pair<int, int>> dist;
vector<pair<int, int>> pt;
void DFS2(int index, int last, int d, int target)
{
d++;
for (auto node : adj[index])
{
if (node.first == last) continue;
if (d == target)
pt.push_back({node.second, node.first});
else
DFS2(node.first, index, d, target);
}
}
void dist_DFS(int index, int last, int d)
{
for (auto node : adj[index])
{
if (node.first == last) continue;
city[node.second] = node.first;
dist.push_back({d, node.second});
dist_DFS(node.first, index, d+1);
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
const int M = U.size();
adj = vector<vector<pair<int, int>>>(N);
for (int i = 0; i < M; i++)
{
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
city.resize(M);
dist_DFS(0, 0, 0);
sort(dist.begin(), dist.end());
ll dst = ask(vector<int>(M));
cerr << "Dist: " << dst << '\n';
// Find placement of A or B in the graph
int l = 0, r = M - 1;
while (l < r)
{
vector<int> w(M);
int c = (l + r + 1) / 2;
for (int i = c; i < M; i++)
w[dist[i].second] = 1;
if (ask(w) == dst)
r = c - 1;
else
l = c;
}
int S = city[dist[l].second];
cerr << "S: " << S << ' ';
DFS2(S, S, 0, dst);
l = 0; r = pt.size() - 1;
while (l < r)
{
vector<int> w(M);
int c = (l + r + 1) / 2;
for (int i = c; i < pt.size(); i++)
w[pt[i].first] = 1;
if (ask(w) == dst)
r = c - 1;
else
l = c;
}
int T = pt[l].second;
cerr << "T: " << T << '\n';
answer(S, T);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i = c; i < pt.size(); i++)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
1368 KB |
Output is correct |
3 |
Runtime error |
100 ms |
17228 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2328 KB |
Output is correct |
2 |
Incorrect |
15 ms |
4052 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1272 KB |
Output is correct |
3 |
Incorrect |
65 ms |
7116 KB |
Output is incorrect: {s, t} is wrong. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
199 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |