結果
問題 | No.1424 Ultrapalindrome |
ユーザー | nephrologist |
提出日時 | 2021-03-12 22:01:58 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,284 bytes |
コンパイル時間 | 197 ms |
コンパイル使用メモリ | 82,152 KB |
実行使用メモリ | 102,428 KB |
最終ジャッジ日時 | 2024-10-14 12:27:13 |
合計ジャッジ時間 | 4,722 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,100 KB |
testcase_01 | AC | 41 ms
55,008 KB |
testcase_02 | AC | 42 ms
55,124 KB |
testcase_03 | AC | 43 ms
54,648 KB |
testcase_04 | AC | 42 ms
54,224 KB |
testcase_05 | AC | 43 ms
53,968 KB |
testcase_06 | AC | 43 ms
54,172 KB |
testcase_07 | AC | 43 ms
53,928 KB |
testcase_08 | WA | - |
testcase_09 | AC | 165 ms
89,684 KB |
testcase_10 | AC | 171 ms
89,608 KB |
testcase_11 | AC | 129 ms
84,028 KB |
testcase_12 | AC | 158 ms
88,864 KB |
testcase_13 | AC | 94 ms
79,296 KB |
testcase_14 | AC | 138 ms
84,716 KB |
testcase_15 | AC | 43 ms
55,916 KB |
testcase_16 | AC | 122 ms
83,216 KB |
testcase_17 | AC | 136 ms
84,444 KB |
testcase_18 | AC | 133 ms
81,672 KB |
testcase_19 | AC | 166 ms
85,192 KB |
testcase_20 | AC | 95 ms
78,548 KB |
testcase_21 | AC | 139 ms
82,968 KB |
testcase_22 | AC | 121 ms
80,800 KB |
testcase_23 | AC | 71 ms
74,300 KB |
testcase_24 | AC | 92 ms
78,292 KB |
testcase_25 | AC | 92 ms
78,256 KB |
testcase_26 | AC | 186 ms
86,952 KB |
testcase_27 | WA | - |
testcase_28 | AC | 115 ms
91,188 KB |
testcase_29 | AC | 117 ms
91,316 KB |
testcase_30 | AC | 135 ms
102,428 KB |
testcase_31 | AC | 122 ms
101,624 KB |
ソースコード
import sys from collections import deque input = sys.stdin.buffer.readline n = int(input()) graph = [[] for _ in range(n)] deg1 = [0] * n deg2 = [0] * n for _ in range(n - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) deg1[a] += 1 deg1[b] += 1 root = -1 kouho = deque() haji = [] dist1 = [-1] * n done = [0] * n for i in range(n): if deg1[i] != 1: root = i if deg1[i] == 1: haji.append(i) def ok(): print("Yes") exit() def ng(): print("No") exit() if n == 2: ok() if root == -1: if n == 2: ok() else: ng() # bfs # print("kouho", kouho) v = haji[0] dist1[v] = 0 kouho.append(v) while kouho: v = kouho.popleft() d = dist1[v] for u in graph[v]: if dist1[u] == -1: dist1[u] = d + 1 kouho.append(u) temp = dist1[haji[1]] for v in haji[1:]: if dist1[v] != temp: ng() dist2 = [-1] * n v = haji[-1] dist2[v] = 0 kouho.append(v) while kouho: v = kouho.popleft() d = dist2[v] for u in graph[v]: if dist2[u] == -1: dist2[u] = d + 1 kouho.append(u) temp = dist2[haji[0]] for v in haji[:-1]: if dist2[v] != temp: ng() ok()