提出 #38874322
ソースコード 拡げる
Copy
Copy
- #include <stdio.h>
- #include <stdlib.h>
-
- int ec[114514], *es[114514];
-
- void ae(int f, int t) {
- es[f] = realloc(es[f], sizeof(*es[f]) * (ec[f] + 1));
- if (es[f] == NULL) exit(2);
- es[f][ec[f]++] = t;
- }
-
- int from[114514];
-
- int q[114514];
-
- int main(void) {
- int N, M;
- int i;
- int qs, qe;
- if (scanf("%d%d", &N, &M) != 2) return 1;
- for (i = 0; i < M; i++) {
- int A, B;
- if (scanf("%d%d", &A, &B) != 2) return 1;
- ae(A, B);
- ae(B, A);
- }
- from[N] = N;
- q[0] = N;
- qs = 0;
- qe = 1;
- while (qs < qe) {
- int c = q[qs++];
- for (i = 0; i < ec[c]; i++) {
- int next = es[c][i];
- if (from[next] == 0) {
- from[next] = c;
- q[qe++] = next;
- }
- }
- }
- putchar('1');
- do {
- i = from[i];
- printf(" %d", i);
- } while (i != N);
- putchar('\n');
- return 0;
- }
#include <stdio.h>
#include <stdlib.h>
int ec[114514], *es[114514];
void ae(int f, int t) {
es[f] = realloc(es[f], sizeof(*es[f]) * (ec[f] + 1));
if (es[f] == NULL) exit(2);
es[f][ec[f]++] = t;
}
int from[114514];
int q[114514];
int main(void) {
int N, M;
int i;
int qs, qe;
if (scanf("%d%d", &N, &M) != 2) return 1;
for (i = 0; i < M; i++) {
int A, B;
if (scanf("%d%d", &A, &B) != 2) return 1;
ae(A, B);
ae(B, A);
}
from[N] = N;
q[0] = N;
qs = 0;
qe = 1;
while (qs < qe) {
int c = q[qs++];
for (i = 0; i < ec[c]; i++) {
int next = es[c][i];
if (from[next] == 0) {
from[next] = c;
q[qe++] = next;
}
}
}
putchar('1');
do {
i = from[i];
printf(" %d", i);
} while (i != N);
putchar('\n');
return 0;
}
提出情報
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
0 / 1000 |
結果 |
|
|
セット名 |
テストケース |
Sample |
sample00.txt, sample01.txt |
All |
00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, sample00.txt, sample01.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
00.txt |
AC |
5 ms |
1852 KB |
01.txt |
AC |
3 ms |
1852 KB |
02.txt |
AC |
29 ms |
3168 KB |
03.txt |
WA |
12 ms |
2212 KB |
04.txt |
WA |
28 ms |
4588 KB |
05.txt |
AC |
33 ms |
3864 KB |
06.txt |
AC |
38 ms |
6764 KB |
07.txt |
AC |
47 ms |
6752 KB |
sample00.txt |
AC |
6 ms |
1728 KB |
sample01.txt |
AC |
1 ms |
1632 KB |