結果

問題 No.1601 With Animals into Institute
ユーザー 👑 ygussany
提出日時 2021-05-22 19:25:20
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,471 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 31,616 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-07-02 02:02:49
合計ジャッジ時間 22,917 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 12
権限があれば一括ダウンロードができます

ソースコード

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