답안 #1021944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021944 2024-07-13T08:03:44 Z fv3 통행료 (IOI18_highway) C++14
51 / 100
203 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<pair<int, pair<int, int>>> edges;
void find_distances(int index, int last, int dist)
{
	dist += 1;
	for (auto node : adj[index])
	{
		if (node.first == last) continue;
		edges.push_back({dist, node});
		find_distances(node.first, index, dist);
	}
}

int find_S(ll dist)
{
	// Sort all edges by bfs_distance 
	// from arbitrary root node (0)	

	find_distances(0, 0, 0);
	sort(edges.begin(), edges.end());

	int l = 0, r = edgeCnt - 1;
	while (l < r)
	{
		int c = (l + r + 1) / 2;

		vector<int> w(edgeCnt);
		for (int i = c; i <= r; i++)
			w[edges[i].second.second] = 1;

		ll cur_dist = ask(w);
		if (cur_dist == dist)
			r = c - 1;
		else
			l = c;
	}

	return edges[l].second.first;
}

int bfs_dist;
vector<pair<int, int>> sus_edges;
void find_sus_edges(int index, int last, int dist)
{
	dist += 1;

	for (auto node : adj[index])
	{
		if (node.first == last) continue;
		if (dist == bfs_dist)
			sus_edges.push_back(node);
		else
			find_sus_edges(node.first, index, dist);
	}
}

int find_T(int root, ll dist)
{
	find_sus_edges(root, root, 0);

	int l = 0, r = sus_edges.size() - 1;
	while (l < r)
	{
		int c = (l + r + 1) / 2;

		vector<int> w(edgeCnt);
		for (int i = c; i <= r; i++)
			w[sus_edges[i].second] = 1;

		ll cur_dist = ask(w);
		if (cur_dist == dist)
			r = c - 1;
		else
			l = c;
	}

	return sus_edges[l].first;
}

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});
	}

	ll dist = ask(vector<int>(edgeCnt));
	bfs_dist = dist / A;

	int S = find_S(dist);
	int T = find_T(S, dist);

	//cerr << "Guess: S = " << S << ", T = " << T << '\n';
	answer(S, T);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 1488 KB Output is correct
3 Correct 76 ms 9068 KB Output is correct
4 Correct 84 ms 9068 KB Output is correct
5 Correct 75 ms 9068 KB Output is correct
6 Correct 83 ms 9084 KB Output is correct
7 Correct 79 ms 9068 KB Output is correct
8 Correct 82 ms 9324 KB Output is correct
9 Correct 78 ms 9068 KB Output is correct
10 Correct 82 ms 9280 KB Output is correct
11 Correct 72 ms 10860 KB Output is correct
12 Correct 76 ms 11624 KB Output is correct
13 Correct 78 ms 11116 KB Output is correct
14 Correct 82 ms 10348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2512 KB Output is correct
2 Correct 14 ms 4464 KB Output is correct
3 Correct 22 ms 6292 KB Output is correct
4 Correct 66 ms 18268 KB Output is correct
5 Correct 66 ms 18024 KB Output is correct
6 Correct 78 ms 18052 KB Output is correct
7 Correct 68 ms 18256 KB Output is correct
8 Correct 64 ms 18024 KB Output is correct
9 Correct 63 ms 17960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 1492 KB Output is correct
3 Correct 67 ms 7688 KB Output is correct
4 Correct 78 ms 9084 KB Output is correct
5 Correct 74 ms 9068 KB Output is correct
6 Correct 89 ms 9068 KB Output is correct
7 Correct 72 ms 9084 KB Output is correct
8 Correct 72 ms 9084 KB Output is correct
9 Correct 86 ms 9088 KB Output is correct
10 Correct 91 ms 9084 KB Output is correct
11 Correct 84 ms 10092 KB Output is correct
12 Correct 89 ms 12224 KB Output is correct
13 Correct 87 ms 11400 KB Output is correct
14 Correct 83 ms 11708 KB Output is correct
15 Correct 81 ms 9068 KB Output is correct
16 Correct 74 ms 9088 KB Output is correct
17 Correct 91 ms 11628 KB Output is correct
18 Correct 80 ms 10988 KB Output is correct
19 Correct 75 ms 9104 KB Output is correct
20 Correct 75 ms 12908 KB Output is correct
21 Correct 70 ms 10340 KB Output is correct
22 Correct 77 ms 10412 KB Output is correct
23 Correct 82 ms 9560 KB Output is correct
24 Correct 74 ms 10332 KB Output is correct
25 Correct 87 ms 16488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 203 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 200 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -