結果

問題 No.1480 Many Complete Graphs
ユーザー 👑 ygussanyygussany
提出日時 2021-03-21 10:11:27
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,537 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 30,472 KB
実行使用メモリ 23,204 KB
最終ジャッジ日時 2023-09-16 02:43:35
合計ジャッジ時間 5,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,256 KB
testcase_01 AC 3 ms
11,024 KB
testcase_02 AC 3 ms
10,324 KB
testcase_03 AC 3 ms
9,928 KB
testcase_04 AC 3 ms
11,088 KB
testcase_05 AC 3 ms
10,512 KB
testcase_06 AC 3 ms
9,904 KB
testcase_07 AC 3 ms
10,476 KB
testcase_08 AC 3 ms
10,768 KB
testcase_09 AC 3 ms
10,620 KB
testcase_10 AC 3 ms
10,896 KB
testcase_11 AC 4 ms
10,936 KB
testcase_12 AC 3 ms
10,500 KB
testcase_13 AC 10 ms
13,532 KB
testcase_14 AC 8 ms
14,228 KB
testcase_15 AC 18 ms
15,060 KB
testcase_16 AC 11 ms
14,116 KB
testcase_17 AC 12 ms
12,956 KB
testcase_18 AC 5 ms
11,768 KB
testcase_19 AC 12 ms
13,176 KB
testcase_20 AC 18 ms
14,428 KB
testcase_21 AC 10 ms
14,920 KB
testcase_22 AC 7 ms
13,680 KB
testcase_23 AC 20 ms
19,124 KB
testcase_24 AC 30 ms
19,048 KB
testcase_25 AC 38 ms
18,988 KB
testcase_26 AC 42 ms
21,040 KB
testcase_27 AC 34 ms
19,204 KB
testcase_28 AC 38 ms
21,100 KB
testcase_29 AC 38 ms
19,112 KB
testcase_30 AC 36 ms
21,104 KB
testcase_31 AC 39 ms
21,260 KB
testcase_32 AC 35 ms
19,188 KB
testcase_33 AC 36 ms
23,148 KB
testcase_34 AC 40 ms
23,140 KB
testcase_35 AC 37 ms
23,176 KB
testcase_36 AC 35 ms
21,096 KB
testcase_37 AC 36 ms
19,052 KB
testcase_38 AC 36 ms
19,068 KB
testcase_39 AC 35 ms
19,052 KB
testcase_40 AC 35 ms
21,144 KB
testcase_41 AC 34 ms
21,032 KB
testcase_42 AC 36 ms
18,980 KB
testcase_43 AC 35 ms
19,060 KB
testcase_44 AC 36 ms
19,060 KB
testcase_45 AC 38 ms
19,136 KB
testcase_46 AC 36 ms
19,152 KB
testcase_47 AC 78 ms
21,092 KB
testcase_48 AC 74 ms
21,036 KB
testcase_49 AC 77 ms
21,160 KB
testcase_50 AC 30 ms
21,076 KB
testcase_51 AC 79 ms
21,032 KB
testcase_52 AC 52 ms
21,096 KB
testcase_53 AC 58 ms
21,124 KB
testcase_54 AC 54 ms
19,132 KB
testcase_55 AC 53 ms
19,048 KB
testcase_56 AC 54 ms
21,096 KB
testcase_57 AC 30 ms
21,224 KB
testcase_58 AC 41 ms
23,204 KB
evil_aftercontest.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

typedef struct {
	long long key;
	int id;
} data;
 
typedef struct {
	data obj[400001];
	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;
}

int main()
{
	int i, j, k, m, n, u, w, N, M;
	long long c;
	list *adj[500001] = {}, e[400001], *p;
	scanf("%d %d", &N, &M);
	for (i = 1, m = 0, n = N; i <= M; i++, n += 4) {
		scanf("%d %lld", &k, &c);
		for (j = 1; j <= k; j++) {
			scanf("%d", &u);
			if (u % 2 == 0) {
				w = n + 1;
				e[m].v = w;
				e[m].cost = c + u / 2;
				e[m].next = adj[u];
				adj[u] = &(e[m++]);
				w = n + 2;
				e[m].v = w;
				e[m].cost = c + u / 2;
				e[m].next = adj[u];
				adj[u] = &(e[m++]);
				w = n + 1;
				e[m].v = u;
				e[m].cost = u / 2;
				e[m].next = adj[w];
				adj[w] = &(e[m++]);
				w = n + 3;
				e[m].v = u;
				e[m].cost = u / 2;
				e[m].next = adj[w];
				adj[w] = &(e[m++]);
			} else {
				w = n + 3;
				e[m].v = w;
				e[m].cost = c + u / 2 + 1;
				e[m].next = adj[u];
				adj[u] = &(e[m++]);
				w = n + 4;
				e[m].v = w;
				e[m].cost = c + u / 2 + 1;
				e[m].next = adj[u];
				adj[u] = &(e[m++]);
				w = n + 2;
				e[m].v = u;
				e[m].cost = u / 2 + 1;
				e[m].next = adj[w];
				adj[w] = &(e[m++]);
				w = n + 4;
				e[m].v = u;
				e[m].cost = u / 2;
				e[m].next = adj[w];
				adj[w] = &(e[m++]);
			}
		}
	}
	
	const long long sup = 1LL << 60;
	long long dist[500001];
	min_heap h;
	data d;
	for (u = 1; u <= n; u++) dist[u] = sup;
	dist[1] = 0;
	h.size = 0;
	d.key = 0;
	d.id = 1;
	push(d, &h);
	while (h.size > 0) {
		d = pop(&h);
		u = d.id;
		if (d.key != dist[u]) continue;
		
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (dist[w] > dist[u] + p->cost) {
				dist[w] = dist[u] + p->cost;
				d.key = dist[w];
				d.id = w;
				push(d, &h);
			}
		}
	}
	if (dist[N] == sup) printf("-1\n");
	else printf("%lld\n", dist[N]);
	fflush(stdout);
	return 0;
}
0