結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2019-07-10 06:42:10 |
言語 | C (gcc 13.3.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,885 bytes |
コンパイル時間 | 377 ms |
コンパイル使用メモリ | 31,488 KB |
実行使用メモリ | 29,824 KB |
最終ジャッジ日時 | 2024-11-23 19:34:04 |
合計ジャッジ時間 | 7,461 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 TLE * 1 |
コンパイルメッセージ
main.c: In function 'in': main.c:11:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 11 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:19:24: note: in expansion of macro 'gc' 19 | int n = 0, c = gc(); | ^~ main.c: In function 'out': main.c:12:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration] 12 | #define pc(c) putchar_unlocked(c) | ^~~~~~~~~~~~~~~~ main.c:29:21: note: in expansion of macro 'pc' 29 | while (i--) pc(b[i]); | ^~
ソースコード
// yukicoder: No.807 umg tours // 2019.7.10 bal4u #include <stdio.h> #include <stdlib.h> #include <string.h> typedef long long ll; #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void out(long n) { // 正整数の表示(出力) int i; char b[20]; i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); pc('\n'); } #define INF 0x33 #define QMAX 1000005 #define MAX 100005 int *to[MAX], *dis[MAX], hi[MAX]; int N; ll ma[MAX], mi[MAX]; int q[QMAX], top, end; // queue void bfs() { int i, a, b, f; memset(mi, INF, sizeof(ll)*N); memset(ma, INF, sizeof(ll)*N); for (i = 0; i < hi[0]; i++) { b = to[0][i]; q[end++] = b, ma[b] = dis[0][i], mi[b] = 0; } while (top != end) { a = q[top++]; // printf("a=%d, ma=%lld, mi=%lld\n", a, ma[a], mi[a]); for (i = 0; i < hi[a]; i++) { b = to[a][i], f = 0; if (ma[b] > dis[a][i]+ma[a]) ma[b] = ma[a] + dis[a][i], f = 1; if (mi[b] > dis[a][i]+mi[a]) mi[b] = mi[a] + dis[a][i], f = 1; if (mi[b] > ma[a]) mi[b] = ma[a], f = 1; if (f) q[end++] = b; } } } int main() { int i, k, a, b, c, M; int *memo, sz; N = in(), M = in(); memo = malloc(sizeof(int)*M*3); sz = 0; while (M--) { memo[sz++] = a = in()-1, memo[sz++] = b = in()-1, memo[sz++] = in(); hi[a]++, hi[b]++; } for (i = 0; i < N; i++) if (hi[i]) { to[i] = malloc(sizeof(int)*hi[i]); dis[i] = malloc(sizeof(int)*hi[i]); } memset(hi, 0, sizeof(hi)); i = 0; while (i < sz) { a = memo[i++], b = memo[i++], c = memo[i++]; k = hi[a]++, to[a][k] = b, dis[a][k] = c; k = hi[b]++, to[b][k] = a, dis[b][k] = c; } bfs(); pc('0'), pc('\n'); for (i = 1; i < N; i++) out(ma[i] + mi[i]); return 0; }