Submission #1697866


Source Code Expand

#include <cstdio>
#include <vector>
#include <algorithm>
const int xn = 131073;
std::vector < std::pair < int, int > > V[xn];
int N, q[xn];
std::vector < std::pair < long long, long long > > ans[xn];
void merge(auto &O, const auto &V0, const auto &V1, long long E0, long long E1, long long LIM)
{
	O.clear();
	std::vector < std::pair < long long, long long > > TMP;
	for (auto &i : V0)
	{
		auto it = std::upper_bound(V1.begin(), V1.end(), std::make_pair(LIM - E0 - E1 - i.second, 1LL << 60));
		if (it != V1.begin())
		{
			std::pair < long long, long long > To_Push_back = { i.first + E0, (it - 1) -> second + E1 };
			TMP.push_back(To_Push_back);
			std::swap(To_Push_back.first, To_Push_back.second);
			TMP.push_back(To_Push_back);
		}
	}
	std::sort(TMP.begin(), TMP.end());
	for (auto i : TMP)
		if (O.empty() || i.second < O.back().second)
			O.push_back(i);
}
bool check(long long mid)
{
	for (int i = N; i; i--)
	{
		int u = q[i];
		if (V[u].empty())
			ans[u] = { { 0, 0 } };
		else
			merge(ans[u], ans[V[u][0].first], ans[V[u][1].first], V[u][0].second, V[u][1].second, mid);
		if (ans[u].empty())
			return false;
	}
	return true;
}
int main()
{
	scanf("%d", &N);
	for (int i = 2, f, l; i <= N; i++)
	{
		scanf("%d%d", &f, &l);
		V[f].push_back({ i, l });
	}
	int H = 0, T = 1;
	q[1] = 1;
	while (H < T)
	{
		int u = q[++H];
		for (auto v : V[u])
			q[++T] = v.first;
	}
	long long l = 0, r = 1LL << 40;
	while (l < r)
	{
		long long m = l + r >> 1;
		if (check(m))
			r = m;
		else
			l = m + 1;
	}
	printf("%lld\n", l);
	return 0;
}

Submission Info

Submission Time
Task E - Shik and Travel
User NiroBC
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 1617 Byte
Status AC
Exec Time 860 ms
Memory 31364 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:44:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:47:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &f, &l);
                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1400 / 1400
Status
AC × 4
AC × 54
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt, example3.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, example0.txt, example1.txt, example2.txt, example3.txt
Case Name Status Exec Time Memory
000.txt AC 10 ms 7040 KB
001.txt AC 10 ms 7040 KB
002.txt AC 10 ms 7040 KB
003.txt AC 10 ms 7040 KB
004.txt AC 10 ms 7040 KB
005.txt AC 10 ms 7040 KB
006.txt AC 10 ms 7040 KB
007.txt AC 10 ms 7040 KB
008.txt AC 10 ms 7040 KB
009.txt AC 10 ms 7040 KB
010.txt AC 515 ms 14080 KB
011.txt AC 506 ms 14080 KB
012.txt AC 505 ms 14080 KB
013.txt AC 505 ms 14080 KB
014.txt AC 477 ms 14080 KB
015.txt AC 485 ms 14080 KB
016.txt AC 490 ms 14080 KB
017.txt AC 479 ms 14080 KB
018.txt AC 484 ms 14080 KB
019.txt AC 486 ms 13952 KB
020.txt AC 471 ms 14080 KB
021.txt AC 474 ms 14080 KB
022.txt AC 612 ms 14080 KB
023.txt AC 476 ms 14080 KB
024.txt AC 477 ms 14080 KB
025.txt AC 498 ms 14080 KB
026.txt AC 449 ms 13568 KB
027.txt AC 496 ms 14080 KB
028.txt AC 440 ms 13568 KB
029.txt AC 437 ms 13568 KB
030.txt AC 377 ms 14080 KB
031.txt AC 460 ms 14080 KB
032.txt AC 463 ms 14080 KB
033.txt AC 378 ms 14080 KB
034.txt AC 378 ms 14080 KB
035.txt AC 451 ms 14080 KB
036.txt AC 378 ms 14080 KB
037.txt AC 369 ms 13952 KB
038.txt AC 378 ms 14080 KB
039.txt AC 364 ms 13056 KB
040.txt AC 724 ms 31236 KB
041.txt AC 860 ms 31364 KB
042.txt AC 856 ms 31364 KB
043.txt AC 852 ms 31364 KB
044.txt AC 191 ms 14080 KB
045.txt AC 307 ms 14080 KB
046.txt AC 306 ms 14080 KB
047.txt AC 306 ms 14080 KB
048.txt AC 309 ms 14080 KB
049.txt AC 4 ms 7040 KB
example0.txt AC 3 ms 6912 KB
example1.txt AC 3 ms 6912 KB
example2.txt AC 3 ms 6912 KB
example3.txt AC 3 ms 6912 KB