結果

問題 No.1602 With Animals into Institute 2
ユーザー 👑 ygussanyygussany
提出日時 2021-06-06 16:02:24
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,325 bytes
コンパイル時間 1,356 ms
コンパイル使用メモリ 30,092 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 19:01:23
合計ジャッジ時間 5,809 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
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 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

const long long sup = 1LL << 60;

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

long long DFS(list* adj[], int u, int t, int flag[], int label)
{
	if (u == t) {
		if (label == 0) return sup;
		else return 0;
	} else flag[u] = 1;
	
	int w;
	long long ans = sup;
	list *p;
	for (p = adj[u]; p != NULL; p = p->next) {
		w = p->v;
		if (flag[w] != 0) continue;
		chmin(&ans, DFS(adj, w, t, flag, label ^ p->x) + p->cost);
	}
	flag[u] = 0;
	return ans;
}

int main()
{
	int i, k, N, M, K, u, w, c, x, bit[31];
	char X[31];
	list *adj[51] = {}, e[1001];
	scanf("%d %d %d", &N, &M, &K);
	if (N > 50 || M > 500) return 0;
	for (k = 1, bit[0] = 1; k < K; k++) bit[k] = bit[k-1] << 1;
	for (i = 0; i < M; i++) {
		scanf("%d %d %d %s", &u, &w, &c, X);
		for (k = 0, x = 0; k < K; k++) if (X[k] == '1') x |= bit[k];
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].id = i;
		e[i*2+1].id = i;
		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]);
	}
	
	int flag[51];
	long long ans;
	for (u = 1; u < N; u++) {
		ans = DFS(adj, u, N, flag, 0);
		printf("%lld\n", (ans == sup)? -1: ans);
	}
	fflush(stdout);
	return 0;
}
0