이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long ll;
int edgeCnt;
vector<vector<pair<int, int>>> adj;
vector<int> connectedCity;
void DFS_from_root(int index, int last)
{
for (auto node : adj[index])
{
if (node.first == last) continue;
connectedCity[node.second] = node.first;
}
}
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;
dist.push_back({d, node.second});
dist_DFS(node.first, index, d + 1);
}
}
int findT(int dist)
{
int l = 0, r = pt.size() - 1;
while (l < r)
{
vector<int> w(edgeCnt);
int c = (l + r + 1) / 2;
for (int i = c; i < pt.size(); i++)
w[pt[i].first] = 1;
if (ask(w) == dist)
r = c - 1;
else
l = c;
}
return connectedCity[pt[l].second];
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
edgeCnt = U.size();
adj = vector<vector<pair<int, int>>>(N);
for (int i = 0; i < edgeCnt; i++)
{
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
connectedCity.resize(edgeCnt);
DFS_from_root(0, 0);
dist_DFS(0, 0, 0);
sort(dist.begin(), dist.end());
ll dst = ask(vector<int>(edgeCnt));
cerr << "Dist: " << dst << '\n';
int S = 0;
cerr << "S: " << S << ' ';
DFS2(S, S, 0, dst);
int T = findT(dst);
cerr << "T: " << T << '\n';
answer(S, T);
}
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp: In function 'int findT(int)':
highway.cpp:54: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]
54 | for (int i = c; i < pt.size(); i++)
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |