結果
問題 | No.1424 Ultrapalindrome |
ユーザー | 小野寺健 |
提出日時 | 2021-05-20 15:11:19 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,527 bytes |
コンパイル時間 | 3,818 ms |
コンパイル使用メモリ | 78,820 KB |
実行使用メモリ | 82,956 KB |
最終ジャッジ日時 | 2024-04-18 14:03:56 |
合計ジャッジ時間 | 16,837 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 140 ms
60,996 KB |
testcase_01 | AC | 153 ms
53,760 KB |
testcase_02 | AC | 148 ms
54,020 KB |
testcase_03 | AC | 146 ms
53,820 KB |
testcase_04 | AC | 139 ms
54,068 KB |
testcase_05 | AC | 138 ms
53,836 KB |
testcase_06 | AC | 145 ms
54,168 KB |
testcase_07 | AC | 145 ms
54,036 KB |
testcase_08 | AC | 142 ms
54,168 KB |
testcase_09 | AC | 1,106 ms
79,864 KB |
testcase_10 | AC | 1,033 ms
79,956 KB |
testcase_11 | AC | 808 ms
72,052 KB |
testcase_12 | AC | 1,169 ms
79,240 KB |
testcase_13 | AC | 529 ms
61,336 KB |
testcase_14 | AC | 903 ms
73,396 KB |
testcase_15 | AC | 178 ms
54,220 KB |
testcase_16 | AC | 820 ms
65,772 KB |
testcase_17 | AC | 988 ms
72,796 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.util.Arrays; public class No1424 { private static int N; private static int[] P; private static List<Integer[]> Edge; private static List<Integer> S; public static void main(String[] args) { Scanner scan = new Scanner(System.in); N = scan.nextInt(); P = new int[N]; Edge = new ArrayList<Integer[]>(); for (int i=0; i < N-1; i++) { int v = scan.nextInt() - 1; int u = scan.nextInt() - 1; P[v]++; P[u]++; Edge.add(new Integer[] {v, u}); Edge.add(new Integer[] {u, v}); } scan.close(); S = new ArrayList<Integer>(); for (int i=0; i < N; i++) { if (P[i] == 1) { S.add(i); } } int res = -1; for (int i=0; i < S.size()-1; i++) { int v = getPath(S.get(i), i); if (v < 0) { System.out.println("No"); return; } else if (res < 0) { res = v; } else if (res != v) { System.out.println("No"); return; } } System.out.println("Yes"); } private static int getPath(int s, int i) { int[] D = new int[N]; Arrays.fill(D, Integer.MAX_VALUE); D[s] = 0; while (true) { boolean update = false; for (Integer[] e : Edge) { if (D[e[0]] != Integer.MAX_VALUE && D[e[1]] > D[e[0]] + 1) { D[e[1]] = D[e[0]] + 1; update = true; } } if (!update) { break; } } int res = -1; for (int e : S.subList(i+1, S.size())) { if (res < 0) { res = D[e]; } else if (res != D[e]) { return -1; } } return res; } }