結果

問題 No.2387 Yokan Factory
ユーザー pengin_2000pengin_2000
提出日時 2023-07-21 22:26:42
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 425 ms / 5,000 ms
コード長 2,990 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 31,484 KB
実行使用メモリ 17,868 KB
最終ジャッジ日時 2023-10-21 22:25:40
合計ジャッジ時間 5,908 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
14,220 KB
testcase_01 AC 3 ms
14,220 KB
testcase_02 AC 3 ms
14,220 KB
testcase_03 AC 2 ms
14,220 KB
testcase_04 AC 3 ms
14,220 KB
testcase_05 AC 3 ms
14,220 KB
testcase_06 AC 2 ms
14,220 KB
testcase_07 AC 3 ms
14,220 KB
testcase_08 AC 3 ms
14,220 KB
testcase_09 AC 3 ms
14,220 KB
testcase_10 AC 3 ms
14,220 KB
testcase_11 AC 2 ms
14,220 KB
testcase_12 AC 2 ms
14,220 KB
testcase_13 AC 3 ms
14,220 KB
testcase_14 AC 2 ms
14,220 KB
testcase_15 AC 298 ms
17,868 KB
testcase_16 AC 273 ms
17,868 KB
testcase_17 AC 412 ms
17,868 KB
testcase_18 AC 308 ms
17,684 KB
testcase_19 AC 270 ms
17,068 KB
testcase_20 AC 231 ms
16,996 KB
testcase_21 AC 425 ms
17,560 KB
testcase_22 AC 207 ms
16,892 KB
testcase_23 AC 280 ms
17,092 KB
testcase_24 AC 118 ms
16,932 KB
testcase_25 AC 161 ms
14,592 KB
testcase_26 AC 303 ms
17,256 KB
testcase_27 AC 408 ms
17,476 KB
testcase_28 AC 5 ms
14,224 KB
testcase_29 AC 5 ms
14,224 KB
testcase_30 AC 5 ms
14,224 KB
testcase_31 AC 5 ms
14,224 KB
testcase_32 AC 4 ms
14,220 KB
testcase_33 AC 3 ms
14,220 KB
testcase_34 AC 5 ms
14,224 KB
testcase_35 AC 5 ms
14,224 KB
testcase_36 AC 3 ms
14,220 KB
testcase_37 AC 3 ms
14,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int u[200005], v[200005];
long long int a[200005], b[200005];
long long int h[1000006], l;
long long int dist[100005];
long long int det[100005];
long long int comp_h(long long int A, long long int B, long long int z)
{
	if (z == 0)
	{
		if (u[h[A]] > u[h[B]])
			return 1;
		else if (u[h[A]] < u[h[B]])
			return -1;
		else if (v[h[A]] > v[h[B]])
			return 1;
		else if (v[h[A]] < v[h[B]])
			return -1;
		else if (a[h[A]] > a[h[B]])
			return 1;
		else
			return -1;
	}
	else if (z == 1)
	{
		if (dist[h[A]] > dist[h[B]])
			return 1;
		else
			return -1;
	}
	else
	{
		if (h[A] > h[B])
			return 1;
		else
			return -1;
	}
}
void swap_h(long long int A, long long int B)
{
	long long int f = h[A];
	h[A] = h[B];
	h[B] = f;
	return;
}
void push(long long int ne, long long int z)
{
	h[l] = ne;
	long long int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p, z) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
long long int pop(long long int z)
{
	l--;
	swap_h(0, l);
	long long int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2, z) > 0)
			{
				if (comp_h(p, 2 * p + 2, z) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1, z) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1, z) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
long long int n, m, x;
long long int c[200005];
long long int sorted_b[200005];
long long int ind[200005];
long long int d(long long int s)
{
	long long int i, j;
	for (i = 0; i < n; i++)
		dist[i] = 2e18;
	dist[0] = 0;
	for (i = 0; i < n; i++)
		det[i] = 0;
	l = 0;
	push(0, 1);
	while (l > 0)
	{
		i = pop(1);
		if (det[i] > 0)
			continue;
		det[i]++;
		j = ind[i];
		for (; u[c[j]] == i; j++)
		{
			if (b[c[j]] < s)
				continue;
			if (dist[v[c[j]]] > dist[i] + a[c[j]])
			{
				dist[v[c[j]]] = dist[i] + a[c[j]];
				push(v[c[j]], 1);
			}
		}
	}
	return dist[n - 1];
}
int main()
{
	scanf("%lld %lld %lld", &n, &m, &x);
	long long int i;
	for (i = 0; i < m; i++)
	{
		scanf("%lld %lld %lld %lld", &u[i], &v[i], &a[i], &b[i]);
		u[i]--;
		v[i]--;
		u[i + m] = v[i];
		v[i + m] = u[i];
		a[i + m] = a[i];
		b[i + m] = b[i];
	}
	m *= 2;
	l = 0;
	for (i = 0; i < m; i++)
		push(i, 0);
	for (i = 0; i < m; i++)
		c[i] = pop(0);
	c[m] = m;
	u[m] = -1;
	long long int min, mid, max;
	for (i = 0; i < n; i++)
	{
		min = -1;
		max = m;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (u[c[mid]] < i)
				min = mid;
			else
				max = mid;
		}
		ind[i] = max;
	}
	l = 0;
	for (i = 0; i < m; i++)
		push(b[i], 2);
	for (i = 0; i < m; i++)
		sorted_b[i] = pop(2);
	min = -1;
	max = m;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (d(sorted_b[mid]) > x)
			max = mid;
		else
			min = mid;
	}
	long long int ans;
	if (min < 0)
		ans = -1;
	else
		ans = sorted_b[min];
	printf("%lld\n", ans);
	return 0;
}
0