結果
問題 | No.92 逃走経路 |
ユーザー |
![]() |
提出日時 | 2019-07-11 21:32:34 |
言語 | C (gcc 13.3.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,071 bytes |
コンパイル時間 | 959 ms |
コンパイル使用メモリ | 32,376 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2024-11-08 10:57:24 |
合計ジャッジ時間 | 2,015 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 RE * 1 |
コンパイルメッセージ
main.c: In function 'in': main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 8 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:16:24: note: in expansion of macro 'gc' 16 | int n = 0, c = gc(); | ^~ main.c: In function 'out': main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration] 9 | #define pc(c) putchar_unlocked(c) | ^~~~~~~~~~~~~~~~ main.c:26:21: note: in expansion of macro 'pc' 26 | while (i--) pc(b[i]); | ^~
ソースコード
// yukicoder: No.92 逃走経路// 2019.7.11 bal4u#include <stdio.h>#include <stdlib.h>#if 1#define gc() getchar_unlocked()#define pc(c) putchar_unlocked(c)#else#define gc() getchar()#define pc(c) putchar(c)#endifint in() { // 非負整数の入力int n = 0, c = gc();do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');return n;}void out(int n) { // 正整数の表示(出力)int i;char b[20];i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;while (i--) pc(b[i]);}#define INF 0x7ffffffftypedef struct { int a, id; } Q;Q q[700000]; int top;typedef struct { int a, b, c; } T;T t[1005]; int M;int to[105][1005], mo[105][1005], hi[105]; int N;int d[1005], K;char ans[105], f[105][105];int aa[2010][2], sz;int cmp(const void *a, const void *b) { return ((T *)a)->c - ((T *)b)->c; }// t[i].c >= x という条件を満たす最小のiint lower_bound(int x) {int m, l = 0, r = M;while (l+1 < r) {m = (l+r)/2;if (t[m].c < x) l = m; else r = m;}return t[l].c < x? r: l;}int dfs(int a, int id) {int i;top = 0, q[top].a = a, q[top++].id = id;while (top) {a = q[--top].a, id = q[top].id;if (id == K) return 1;for (i = 0; i < hi[a]; i++) {if (mo[a][i] == d[id]) q[top].a = to[a][i], q[top++].id = id+1;}}return 0;}int main(){int i, k, a, b, c;N = in(), M = in(), K = in();for (i = 0; i < M; i++) {a = in(), b = in(), c = in();t[i].a = a, t[i].b = b, t[i].c = c;k = hi[a]++, to[a][k] = b, mo[a][k] = c;k = hi[b]++, to[b][k] = a, mo[b][k] = c;}qsort(t, M, sizeof(T), cmp); t[M].c = INF;i = K; while (i--) d[i] = in();i = lower_bound(d[0]);while (t[i].c == d[0]) {a = t[i].a, b = t[i].b;if (!f[a][b]) f[a][b] = 1, aa[sz][0] = t[i].a, aa[sz++][1] = t[i].b;if (!f[b][a]) f[b][a] = 1, aa[sz][0] = t[i].b, aa[sz++][1] = t[i].a;i++;}k = 0; for (i = 0; i < sz; i++) {a = aa[i][0], b = aa[i][1];if (!ans[a] && dfs(b, 1)) ans[a] = 1, k++;}out(k), pc('\n');for (i = 1; i <= N; i++) if (ans[i]) out(i), pc(' ');pc('\n');return 0;}