結果

問題 No.1607 Kth Maximum Card
ユーザー 👑 ygussanyygussany
提出日時 2021-07-16 22:05:25
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 505 ms / 3,500 ms
コード長 1,192 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 29,452 KB
実行使用メモリ 13,556 KB
最終ジャッジ日時 2023-09-20 14:05:06
合計ジャッジ時間 7,916 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,944 KB
testcase_01 AC 2 ms
6,028 KB
testcase_02 AC 1 ms
6,252 KB
testcase_03 AC 2 ms
6,344 KB
testcase_04 AC 2 ms
6,308 KB
testcase_05 AC 2 ms
6,052 KB
testcase_06 AC 1 ms
5,896 KB
testcase_07 AC 2 ms
5,980 KB
testcase_08 AC 317 ms
13,400 KB
testcase_09 AC 207 ms
12,164 KB
testcase_10 AC 321 ms
13,300 KB
testcase_11 AC 47 ms
6,500 KB
testcase_12 AC 187 ms
11,860 KB
testcase_13 AC 29 ms
6,448 KB
testcase_14 AC 34 ms
10,168 KB
testcase_15 AC 203 ms
12,620 KB
testcase_16 AC 30 ms
8,720 KB
testcase_17 AC 12 ms
5,972 KB
testcase_18 AC 114 ms
12,404 KB
testcase_19 AC 67 ms
10,324 KB
testcase_20 AC 103 ms
8,684 KB
testcase_21 AC 112 ms
11,556 KB
testcase_22 AC 271 ms
13,520 KB
testcase_23 AC 255 ms
13,556 KB
testcase_24 AC 81 ms
8,680 KB
testcase_25 AC 46 ms
8,752 KB
testcase_26 AC 56 ms
9,460 KB
testcase_27 AC 88 ms
10,252 KB
testcase_28 AC 70 ms
10,244 KB
testcase_29 AC 128 ms
11,548 KB
testcase_30 AC 505 ms
13,360 KB
testcase_31 AC 121 ms
10,724 KB
testcase_32 AC 404 ms
12,788 KB
testcase_33 AC 286 ms
10,788 KB
testcase_34 AC 265 ms
10,732 KB
testcase_35 AC 276 ms
10,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct List {
	struct List *next;
	int v, cost;
} list;

int main()
{
	int i, N, M, K, u, w, c;
	list *adj[200001] = {}, e[400001], *p;
	scanf("%d %d %d", &N, &M, &K);
	for (i = 0; i < M; i++) {
		scanf("%d %d %d", &u, &w, &c);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].cost = c;
		e[i*2+1].cost = c;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	const int sup = 1 << 20;
	int l = 0, r = 200000, m, dist[200001], q[400001][2], head, tail;
	while (l < r) {
		m = (l + r) / 2;
		for (u = 2, dist[1] = 0; u <= N; u++) dist[u] = sup;
		head = N;
		tail = N;
		q[tail][0] = 1;
		q[tail++][1] = 0;
		for (; head < tail; head++) {
			u = q[head][0];
			if (q[head][1] != dist[u]) continue;
			for (p = adj[u]; p != NULL; p = p->next) {
				w = p->v;
				if (p->cost <= m && dist[w] > dist[u]) {
					dist[w] = dist[u];
					q[head][0] = w;
					q[head--][1] = dist[w];
				} else if (p->cost > m && dist[w] > dist[u] + 1) {
					dist[w] = dist[u] + 1;
					q[tail][0] = w;
					q[tail++][1] = dist[w];
				}
			}
		}
		if (dist[N] >= K) l = m + 1;
		else r = m;
	}
	printf("%d\n", l);
	fflush(stdout);
	return 0;
}
0