結果

問題 No.1812 Uribo Road
ユーザー ygussanyygussany
提出日時 2021-12-29 15:06:17
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 2,110 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 32,640 KB
実行使用メモリ 172,360 KB
最終ジャッジ日時 2024-04-16 09:08:19
合計ジャッジ時間 7,457 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 9 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 19 ms
5,376 KB
testcase_09 AC 39 ms
5,376 KB
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int bit[13] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096};

typedef struct {
	int key, id[2];
} data;

typedef struct {
	data obj[40000000];
	int size;
} min_heap;

void push(min_heap* h, data x)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key < h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(min_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

typedef struct Edge {
	struct Edge *next;
	int v, cost, flag;
} edge;

int main()
{
	int i, j, N, M, K, u, w, c, R[12];
	edge *adj[10001] = {}, e[40001], *p;
	scanf("%d %d %d", &N, &M, &K);
	for (i = 0; i < K; i++) scanf("%d", &(R[i]));
	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].flag = 0;
		e[i*2+1].flag = 0;
		for (j = 0; j < K; j++) {
			if (R[j] == i + 1) {
				e[i*2].flag = bit[j];
				e[i*2+1].flag = bit[j];
			}
		}
		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 << 30) - 1) << 1;
	int dist[10001][4096];
	data d;
	min_heap h;
	h.size = 0;
	for (u = 1; u <= N; u++) for (i = 0; i < bit[K]; i++) dist[u][i] = sup;
	dist[1][0] = 0;
	d.key = 0;
	d.id[0] = 1;
	d.id[1] = 0;
	push(&h, d);
	while (h.size > 0) {
		d = pop(&h);
		u = d.id[0];
		i = d.id[1];
		if (d.key != dist[u][i]) continue;
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			j = i | p->flag;
			if (dist[w][j] > dist[u][i] + p->cost) {
				dist[w][j] = dist[u][i] + p->cost;
				d.key = dist[w][j];
				d.id[0] = w;
				d.id[1] = j;
				push(&h, d);
			}
		}
	}
	printf("%d\n", dist[N][bit[K]-1]);
	fflush(stdout);
	return 0;
}
0