답안 #1021419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021419 2024-07-12T17:48:59 Z fv3 통행료 (IOI18_highway) C++14
0 / 100
226 ms 262144 KB
#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[i] = 1;

		if (ask(w) == dst)
			r = c - 1;
		else
			l = c;
	}

	int S = (l == -1 ? 0 : city[l]);
	cerr << "S: " << S << '\n';

	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:82: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]
   82 |   for (int i = c; i < pt.size(); i++)
      |                   ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2136 KB Output is correct
2 Incorrect 15 ms 4052 KB Output is incorrect: {s, t} is wrong.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 226 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 208 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -