結果

問題 No.2387 Yokan Factory
ユーザー pengin_2000pengin_2000
提出日時 2023-07-21 22:02:33
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 2,607 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 31,228 KB
実行使用メモリ 21,260 KB
最終ジャッジ日時 2023-10-21 22:04:34
合計ジャッジ時間 8,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
14,184 KB
testcase_01 AC 3 ms
14,184 KB
testcase_02 AC 3 ms
14,184 KB
testcase_03 AC 3 ms
14,184 KB
testcase_04 AC 3 ms
14,184 KB
testcase_05 AC 3 ms
14,184 KB
testcase_06 AC 3 ms
14,184 KB
testcase_07 AC 3 ms
14,184 KB
testcase_08 AC 3 ms
14,184 KB
testcase_09 AC 3 ms
14,184 KB
testcase_10 AC 4 ms
14,184 KB
testcase_11 AC 3 ms
14,184 KB
testcase_12 AC 3 ms
14,184 KB
testcase_13 AC 4 ms
14,184 KB
testcase_14 AC 3 ms
14,184 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int u[200005], v[200005];
long long int h[1000006], l;
long long int dist[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
			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 a[200005], b[200005];
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;
	l = 0;
	push(0, 1);
	while (l > 0)
	{
		i = pop(1);
		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);
	long long int ans = -1;
	for (i = 0; i < m; i++)
	{
		if (d(sorted_b[i]) > x)
			break;
		ans = sorted_b[i];
	}
	printf("%lld\n", ans);
	return 0;
}
0