結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー | mkawa2 |
提出日時 | 2021-10-13 18:19:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 996 ms / 2,500 ms |
コード長 | 2,405 bytes |
コンパイル時間 | 153 ms |
コンパイル使用メモリ | 82,236 KB |
実行使用メモリ | 186,016 KB |
最終ジャッジ日時 | 2024-09-17 16:20:45 |
合計ジャッジ時間 | 36,728 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,528 KB |
testcase_01 | AC | 41 ms
54,016 KB |
testcase_02 | AC | 72 ms
76,320 KB |
testcase_03 | AC | 77 ms
75,904 KB |
testcase_04 | AC | 74 ms
74,112 KB |
testcase_05 | AC | 79 ms
76,608 KB |
testcase_06 | AC | 78 ms
76,544 KB |
testcase_07 | AC | 839 ms
162,776 KB |
testcase_08 | AC | 833 ms
163,304 KB |
testcase_09 | AC | 861 ms
163,044 KB |
testcase_10 | AC | 896 ms
163,440 KB |
testcase_11 | AC | 874 ms
162,676 KB |
testcase_12 | AC | 901 ms
163,488 KB |
testcase_13 | AC | 818 ms
162,964 KB |
testcase_14 | AC | 864 ms
163,480 KB |
testcase_15 | AC | 882 ms
162,796 KB |
testcase_16 | AC | 853 ms
163,156 KB |
testcase_17 | AC | 856 ms
162,708 KB |
testcase_18 | AC | 857 ms
162,204 KB |
testcase_19 | AC | 868 ms
162,032 KB |
testcase_20 | AC | 813 ms
160,144 KB |
testcase_21 | AC | 844 ms
159,992 KB |
testcase_22 | AC | 814 ms
162,776 KB |
testcase_23 | AC | 842 ms
162,536 KB |
testcase_24 | AC | 839 ms
161,772 KB |
testcase_25 | AC | 871 ms
161,012 KB |
testcase_26 | AC | 859 ms
160,968 KB |
testcase_27 | AC | 896 ms
184,444 KB |
testcase_28 | AC | 996 ms
185,688 KB |
testcase_29 | AC | 975 ms
185,116 KB |
testcase_30 | AC | 969 ms
184,864 KB |
testcase_31 | AC | 926 ms
186,016 KB |
testcase_32 | AC | 604 ms
147,864 KB |
testcase_33 | AC | 611 ms
147,956 KB |
testcase_34 | AC | 646 ms
147,988 KB |
testcase_35 | AC | 628 ms
147,824 KB |
testcase_36 | AC | 608 ms
149,144 KB |
testcase_37 | AC | 366 ms
147,388 KB |
testcase_38 | AC | 341 ms
157,828 KB |
testcase_39 | AC | 352 ms
152,468 KB |
testcase_40 | AC | 355 ms
154,472 KB |
testcase_41 | AC | 378 ms
163,208 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 from collections import Counter n, m = LI() aa = LI1() to = [[] for _ in range(n)] for _ in range(n-1): u, v = LI1() to[u].append(v) to[v].append(u) # ***************ここから本体***************** # 設定 root = 0 e = lambda: set() # 単位元 def op(a, b): if isinstance(b, set): return a | b a.add(b) return a def trans_up(u): for a in range(n): if a not in dp[u]: dp[u] = a return def trans_down(u): for a in range(n): if a not in rdp[u]: rdp[u] = a return # dfs順を作る uu = [] stack = [root] par = [-1]*n while stack: u = stack.pop() uu.append(u) vv = [] # ↓変数注意 for v in to[u]: if v == par[u]: continue vv.append(v) par[v] = u stack.append(v) to[u] = vv # print("to",to) # print("par",par) dp = [e() for _ in range(n)] rdp = [0 for _ in range(n)] # 下から更新 for u in uu[::-1]: p = par[u] if p != -1: trans_up(u) dp[p] = op(dp[p], dp[u]) # print("dp",dp) # 上から更新 gg = [-1]*n for u in uu: cnt = Counter(dp[v] for v in to[u]) if u != root: cnt[rdp[u]] += 1 for g in range(n): if cnt[g] == 0: gg[u] = g break for v in to[u]: if cnt[dp[v]] == 1 and dp[v] < gg[u]: rdp[v] = dp[v] else: rdp[v] = gg[u] # print(gg) g = 0 for a in aa: g ^= gg[a] # print(g) if g == 0: print(-1, -1) exit() ln = g.bit_length()-1 for i, a in enumerate(aa): if gg[a] >> ln & 1 == 0: continue for v in to[a]: if g ^ gg[a] ^ dp[v] == 0: print(i+1, v+1) exit() if a != root and g ^ gg[a] ^ rdp[a] == 0: print(i+1, par[a]+1) exit()