結果
問題 |
No.845 最長の切符
|
ユーザー |
![]() |
提出日時 | 2019-06-29 06:57:36 |
言語 | C (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,203 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 30,848 KB |
実行使用メモリ | 8,480 KB |
最終ジャッジ日時 | 2024-07-02 05:23:32 |
合計ジャッジ時間 | 5,044 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 TLE * 1 -- * 14 |
コンパイルメッセージ
main.c: In function 'in': main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 7 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:13:24: note: in expansion of macro 'gc' 13 | int n = 0, c = gc(); | ^~
ソースコード
// yukicoder: No.845 最長の切符 // 2019.6.9 bal4u #include <stdio.h> #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } typedef struct { int a, c, p; } Q; Q q[10000]; int top; int N, M, MASK; int map[17][17]; int to[17][17], ds[17][17], hi[17]; int dfs(int s) { int i, a, b, c, p, ans = 0; top = 1, q[0].a = s, q[0].c = 0, q[0].p = 1<<s; while (top) { a = q[--top].a, c = q[top].c, p = q[top].p; if (c > ans) ans = c; for (i = 0; i < hi[a]; i++) { b = to[a][i]; if (((p | ~(1<<b)) & MASK) == MASK) continue; q[top].a = b, q[top].c = c + ds[a][i], q[top].p = p | (1<<b); top++; } } return ans; } int main() { int k, a, b, c, ans; N = in(), M = in(), MASK = (1<<N)-1; while (M--) { a = in()-1, b = in()-1, c = in(); if (map[a][b] < c) map[a][b] = map[b][a] = c; } for (a = 0; a < N; a++) for (b = 0; b < N; b++) if (a != b) { if (map[a][b]) k = hi[a]++, to[a][k] = b, ds[a][k] = map[a][b]; } ans = 0; for (a = 0; a < N; a++) { if ((k = dfs(a)) > ans) ans = k; } printf("%d\n", ans); return 0; }