結果
問題 | No.1424 Ultrapalindrome |
ユーザー | kuro_B |
提出日時 | 2023-04-06 14:35:48 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,352 bytes |
コンパイル時間 | 221 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 51,072 KB |
最終ジャッジ日時 | 2024-04-10 11:40:30 |
合計ジャッジ時間 | 9,121 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
11,776 KB |
testcase_01 | AC | 39 ms
11,776 KB |
testcase_02 | AC | 39 ms
11,776 KB |
testcase_03 | WA | - |
testcase_04 | AC | 39 ms
11,776 KB |
testcase_05 | WA | - |
testcase_06 | AC | 40 ms
11,648 KB |
testcase_07 | AC | 39 ms
11,648 KB |
testcase_08 | WA | - |
testcase_09 | AC | 476 ms
29,020 KB |
testcase_10 | AC | 483 ms
29,116 KB |
testcase_11 | AC | 296 ms
25,580 KB |
testcase_12 | AC | 393 ms
28,796 KB |
testcase_13 | AC | 131 ms
16,100 KB |
testcase_14 | AC | 368 ms
26,456 KB |
testcase_15 | AC | 41 ms
11,648 KB |
testcase_16 | AC | 267 ms
24,392 KB |
testcase_17 | AC | 308 ms
25,976 KB |
testcase_18 | AC | 218 ms
20,412 KB |
testcase_19 | AC | 355 ms
26,124 KB |
testcase_20 | AC | 99 ms
15,104 KB |
testcase_21 | AC | 345 ms
25,964 KB |
testcase_22 | AC | 170 ms
18,900 KB |
testcase_23 | AC | 60 ms
13,440 KB |
testcase_24 | AC | 101 ms
15,488 KB |
testcase_25 | AC | 96 ms
15,232 KB |
testcase_26 | AC | 428 ms
27,988 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 342 ms
35,408 KB |
testcase_31 | AC | 335 ms
38,508 KB |
ソースコード
###スニペット始まり### import sys, re from copy import copy, deepcopy from math import ceil, floor, sqrt,factorial, gcd, pi, degrees, radians, sin, asin, cos, acos, tan, atan2 from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import permutations, accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce, lru_cache from string import ascii_uppercase, ascii_lowercase from decimal import Decimal, ROUND_HALF_UP #四捨五入用 def input(): return sys.stdin.readline().rstrip('\n') #easy-testのpypyでは再帰数を下げる。 if __file__=='prog.py': sys.setrecursionlimit(10**5) else: sys.setrecursionlimit(10**6) def lcm(a, b): return a * b // gcd(a, b) #3つ以上の最大公約数/最小公倍数 def gcd_v2(l: list): return reduce(gcd, l) def lcm_v2(l: list): return reduce(lcm, l) #nPk def nPk(n, k): return factorial(n) // factorial(n - k) #逆元 def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) INF = float('inf') MOD = 10 ** 9 + 7 ###スニペット終わり### N=int(input()) graph = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) # 有向グラフなら消す dists=[-1]*N def dfs(s, dist): dists[s]=dist for v in graph[s]: if dists[v]==-1: dfs(v, dist+1) dfs(0,0) s=dists.index(max(dists)) #0から一番遠い点を求める。 dists=[-1]*N prev=defaultdict(int) def dfs2(s, dist): dists[s]=dist for v in graph[s]: if dists[v]==-1: dfs2(v, dist+1) prev[v]=s dfs2(s,0) diam=max(dists) #直径 diam_leaf=dists.index(diam) #直径の末端。 if diam%2!=0: print('No') else: #直径が偶数なら可能性あり。 #まずは中心を求める。 center=diam_leaf for _ in range(diam//2): center=prev[center] dist_set=set() visited=[False]*N def dfs(s, dist): visited[s]=True flag=True for v in graph[s]: if not visited[v]: flag=False dfs(v, dist+1) if flag: dist_set.add(dist) dfs(center,0) if len(dist_set)==1: print('Yes') else: print('No')