이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// ll ask(vector<int> w)
// void answer(int a, int b)
vector<vector<pair<int,int>>> adjlist; // node, ind
int n,a,b,m;
vector<int> parentedge;
vector<int> parentnode;
vector<int> preorder;
void dfs(int node, int par){
	preorder.push_back(node);
	for (auto p : adjlist[node]){
		int i = p.first;
		int ni = p.second;
		if (i==par){continue;}
		parentnode[i]=node;
		parentedge[i]=ni;
		dfs(i,node);
	}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	n=N;a=A;b=B;m=U.size();
	adjlist.resize(n);
	parentnode.resize(n,-1);
	parentedge.resize(n,-1);
	for (int i = 0; i<U.size(); i++){
		adjlist[U[i]].push_back({V[i],i});
		adjlist[V[i]].push_back({U[i],i});
	}
	dfs(0,-1);
	// what's the total length of the path?
	vector<int> query(m);
	ll len = ask(query)/a;
	// binary search until path is len*b
	int l = 0, r = n-1;
	while (l<=r){
		int mid = (l+r)/2;
		query.assign(m,0);
		for (int i = 1; i<=mid; i++){
			query[parentedge[preorder[i]]]=1;
		}
		ll ans = ask(query);
		if (ans<len*b){
			l=mid+1;
		} else {
			r=mid-1;
		}
	}
	int root = preorder[l];
	// root at l, then search again
	preorder.clear();
	parentnode[root]=-1;
	parentedge[root]=-1;
	dfs(root,-1);
	l = 0, r = n-1;
	while (l<=r){
		int mid = (l+r)/2;
		query.assign(m,0);
		for (int i = 1; i<=mid; i++){
			query[parentedge[preorder[i]]]=1;
		}
		ll ans = ask(query);
		if (ans<len*b){
			l=mid+1;
		} else {
			r=mid-1;
		}
	}
	//cout<<root<<' '<<preorder[l]<<'\n';
	answer(root,preorder[l]);
}
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 0; i<U.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... |