提出 #38874322


ソースコード 拡げる

Copy
Copy
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int ec[114514], *es[114514];
  5.  
  6. void ae(int f, int t) {
  7. es[f] = realloc(es[f], sizeof(*es[f]) * (ec[f] + 1));
  8. if (es[f] == NULL) exit(2);
  9. es[f][ec[f]++] = t;
  10. }
  11.  
  12. int from[114514];
  13.  
  14. int q[114514];
  15.  
  16. int main(void) {
  17. int N, M;
  18. int i;
  19. int qs, qe;
  20. if (scanf("%d%d", &N, &M) != 2) return 1;
  21. for (i = 0; i < M; i++) {
  22. int A, B;
  23. if (scanf("%d%d", &A, &B) != 2) return 1;
  24. ae(A, B);
  25. ae(B, A);
  26. }
  27. from[N] = N;
  28. q[0] = N;
  29. qs = 0;
  30. qe = 1;
  31. while (qs < qe) {
  32. int c = q[qs++];
  33. for (i = 0; i < ec[c]; i++) {
  34. int next = es[c][i];
  35. if (from[next] == 0) {
  36. from[next] = c;
  37. q[qe++] = next;
  38. }
  39. }
  40. }
  41. putchar('1');
  42. do {
  43. i = from[i];
  44. printf(" %d", i);
  45. } while (i != N);
  46. putchar('\n');
  47. return 0;
  48. }
#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;
}

提出情報

提出日時
問題 B62 - Print a Path
ユーザ mikecat
言語 C (GCC 9.2.1)
得点 0
コード長 806 Byte
結果 WA
実行時間 47 ms
メモリ 6764 KB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 1000
結果
AC × 2
AC × 8
WA × 2
セット名 テストケース
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


2023-02-13 (月)
22:22:56 +00:00