結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー | mkawa2 |
提出日時 | 2021-10-13 12:48:48 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,383 bytes |
コンパイル時間 | 350 ms |
コンパイル使用メモリ | 82,136 KB |
実行使用メモリ | 200,312 KB |
最終ジャッジ日時 | 2024-09-17 16:16:30 |
合計ジャッジ時間 | 42,717 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
59,548 KB |
testcase_01 | AC | 34 ms
52,480 KB |
testcase_02 | AC | 66 ms
75,960 KB |
testcase_03 | AC | 62 ms
74,240 KB |
testcase_04 | AC | 62 ms
74,064 KB |
testcase_05 | AC | 65 ms
74,240 KB |
testcase_06 | AC | 67 ms
75,908 KB |
testcase_07 | AC | 899 ms
171,324 KB |
testcase_08 | AC | 1,018 ms
172,280 KB |
testcase_09 | AC | 970 ms
171,700 KB |
testcase_10 | AC | 870 ms
171,512 KB |
testcase_11 | AC | 930 ms
171,596 KB |
testcase_12 | AC | 894 ms
171,680 KB |
testcase_13 | AC | 924 ms
171,384 KB |
testcase_14 | AC | 902 ms
171,592 KB |
testcase_15 | AC | 915 ms
171,456 KB |
testcase_16 | AC | 910 ms
171,648 KB |
testcase_17 | AC | 952 ms
170,740 KB |
testcase_18 | AC | 941 ms
170,100 KB |
testcase_19 | AC | 923 ms
170,484 KB |
testcase_20 | AC | 878 ms
168,184 KB |
testcase_21 | AC | 881 ms
168,176 KB |
testcase_22 | AC | 952 ms
171,124 KB |
testcase_23 | AC | 935 ms
170,304 KB |
testcase_24 | AC | 881 ms
170,276 KB |
testcase_25 | AC | 937 ms
169,464 KB |
testcase_26 | AC | 943 ms
169,380 KB |
testcase_27 | AC | 1,000 ms
194,684 KB |
testcase_28 | AC | 925 ms
194,364 KB |
testcase_29 | AC | 943 ms
194,736 KB |
testcase_30 | AC | 972 ms
194,628 KB |
testcase_31 | AC | 977 ms
194,876 KB |
testcase_32 | AC | 890 ms
197,608 KB |
testcase_33 | AC | 858 ms
198,752 KB |
testcase_34 | AC | 850 ms
197,480 KB |
testcase_35 | AC | 885 ms
198,252 KB |
testcase_36 | AC | 890 ms
198,372 KB |
testcase_37 | TLE | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
ソースコード
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 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 = [e() 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: cs = e() # ↓変数注意 for v in to[u]: rdp[v] = op(rdp[v], cs) cs = op(cs, dp[v]) cs = op(e(), rdp[u]) for v in to[u][::-1]: rdp[v] = op(rdp[v], cs) trans_down(v) cs = op(cs, dp[v]) for g in range(n): if g not in cs: gg[u] = g # print(u,cs, g) break # print("gg",gg) g = 0 for a in aa: g ^= gg[a] # print(g) if g == 0: print(-1, -1) exit() for i, a in enumerate(aa): 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()