結果

問題 No.1601 With Animals into Institute
ユーザー 👑 ygussanyygussany
提出日時 2021-05-22 19:25:20
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,471 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 30,716 KB
実行使用メモリ 9,940 KB
最終ジャッジ日時 2023-09-14 19:02:13
合計ジャッジ時間 27,649 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 2,116 ms
9,776 KB
testcase_04 AC 2,148 ms
9,924 KB
testcase_05 AC 2,104 ms
9,756 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2,111 ms
9,852 KB
testcase_19 AC 2,148 ms
9,856 KB
testcase_20 AC 2,096 ms
9,844 KB
testcase_21 AC 2,118 ms
9,836 KB
testcase_22 AC 2,130 ms
9,904 KB
testcase_23 AC 2,144 ms
9,772 KB
testcase_24 AC 2,115 ms
9,940 KB
testcase_25 AC 2,122 ms
9,852 KB
testcase_26 AC 2,123 ms
9,760 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 0 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 0 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

void chmin(long long* a, long long b)
{
	if (*a > b) *a = b;
}

void naive(int N, list* adj[], int s, long long ans[])
{
	int i, j, k, u, w;
	const long long sup = 1LL << 60;
	long long dist[1001][1001];
	list *p;
	for (u = 1; u <= N; u++) for (w = 1; w <= N; w++) dist[u][w] = (u == w)? 0: sup;
	for (u = 1; u <= N; u++) for (p = adj[u]; p != NULL; p = p->next) chmin(&(dist[u][p->v]), p->cost);
	for (k = 1; k <= N; k++) {
		for (i = 1; i <= N; i++) {
			for (j = 1; j <= N; j++) {
				if (dist[i][k] == sup || dist[k][j] == sup) continue;
				chmin(&(dist[i][j]), dist[i][k] + dist[k][j]);
			}
		}
	}
	
	int t;
	for (u = 1; u < N; u++) ans[u] = sup;
	for (u = 1; u <= N; u++) {
		for (p = adj[u]; p != NULL; p = p->next) {
			if (p->x == 0) continue;
			w = p->v;
			for (t = 1; t <= N; t++) chmin(&(ans[t]), dist[t][u] + dist[w][s] + p->cost);
		}
	}
}

int main()
{
	int i, N, M, u, w, c, x;
	list *adj[1001] = {}, e[10001];
	scanf("%d %d", &N, &M);
	if (N > 1000) return 0;
	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[1001];
	naive(N, adj, N, ans);
	for (u = 1; u < N; u++) printf("%lld\n", ans[u]);
	fflush(stdout);
	return 0;
}
0