結果

問題 No.1601 With Animals into Institute
ユーザー 👑 ygussanyygussany
提出日時 2021-05-22 19:23:39
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 244 ms / 3,000 ms
コード長 2,046 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 30,476 KB
実行使用メモリ 16,596 KB
最終ジャッジ日時 2023-09-14 19:01:31
合計ジャッジ時間 7,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
6,576 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 5 ms
6,576 KB
testcase_06 AC 240 ms
15,652 KB
testcase_07 AC 242 ms
15,796 KB
testcase_08 AC 240 ms
15,468 KB
testcase_09 AC 244 ms
15,944 KB
testcase_10 AC 240 ms
15,716 KB
testcase_11 AC 231 ms
16,596 KB
testcase_12 AC 230 ms
15,872 KB
testcase_13 AC 224 ms
15,480 KB
testcase_14 AC 224 ms
15,332 KB
testcase_15 AC 227 ms
15,924 KB
testcase_16 AC 226 ms
15,484 KB
testcase_17 AC 220 ms
15,548 KB
testcase_18 AC 5 ms
6,288 KB
testcase_19 AC 4 ms
6,492 KB
testcase_20 AC 4 ms
6,652 KB
testcase_21 AC 4 ms
6,312 KB
testcase_22 AC 4 ms
4,384 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 4 ms
4,384 KB
testcase_26 AC 4 ms
6,692 KB
testcase_27 AC 2 ms
4,752 KB
testcase_28 AC 2 ms
6,796 KB
testcase_29 AC 2 ms
6,672 KB
testcase_30 AC 2 ms
6,624 KB
testcase_31 AC 2 ms
6,532 KB
testcase_32 AC 2 ms
6,464 KB
testcase_33 AC 2 ms
4,504 KB
testcase_34 AC 2 ms
6,544 KB
testcase_35 AC 2 ms
4,728 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
6,780 KB
testcase_38 AC 2 ms
6,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

typedef struct {
	long long key;
	int id;
} data;
 
typedef struct {
	data obj[800001];
	int size;
} min_heap;
 
void push(data x, min_heap* h)
{
	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 = i << 1;
		} else break;
	}
	return output;
}

void solve(int N, list* adj[], int s, long long ans[])
{
	int i, j, u, w, c;
	const long long sup = 1LL << 60;
    long long dist[2][100001];
	list *p;
	min_heap h;
	data d;
	h.size = 0;
	for (u = 1; u <= N; u++) {
		dist[0][u] = sup;
		dist[1][u] = sup;
	}
	dist[0][s] = 0;
	d.key = 0;
	d.id = s;
	push(d, &h);
	while (h.size > 0) {
		d = pop(&h);
		i = (d.id - 1) / N;
		u = d.id - N * i;
		if (d.key != dist[i][u]) continue;
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			c = p->cost;
			j = i | p->x;
			if (dist[j][w] > dist[i][u] + c) {
				dist[j][w] = dist[i][u] + c;
				d.key = dist[j][w];
				d.id = w + N * j;
				push(d, &h);
			}
		}
	}
	for (u = 1; u < N; u++) ans[u] = dist[1][u];
}

int main()
{
	int i, N, M, u, w, c, x;
    list *adj[100001] = {}, e[400001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < M; i++) {
		scanf("%d %d %d %d", &u, &w, &c, &x);
		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].x = x;
		e[i*2+1].x = x;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}

    long long ans[100001];
	solve(N, adj, N, ans);
	for (u = 1; u < N; u++) printf("%lld\n", ans[u]);
	fflush(stdout);
	return 0;
}
0