Submission #1021884

# Submission time Handle Problem Language Result Execution time Memory
1021884 2024-07-13T06:58:04 Z fv3 Highway Tolls (IOI18_highway) C++14
0 / 100
198 ms 262144 KB
#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);
}

Compilation message

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
1 Incorrect 0 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2136 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 198 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 183 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -