結果

問題 No.1153 ねこちゃんゲーム
ユーザー mkawa2mkawa2
提出日時 2021-10-13 18:18:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,377 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 81,740 KB
実行使用メモリ 185,840 KB
最終ジャッジ日時 2023-10-17 19:08:32
合計ジャッジ時間 44,046 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,500 KB
testcase_01 AC 41 ms
55,500 KB
testcase_02 WA -
testcase_03 AC 82 ms
76,168 KB
testcase_04 WA -
testcase_05 AC 82 ms
76,244 KB
testcase_06 WA -
testcase_07 AC 1,056 ms
160,652 KB
testcase_08 AC 1,261 ms
163,352 KB
testcase_09 AC 1,052 ms
162,856 KB
testcase_10 AC 1,041 ms
163,164 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,012 ms
162,632 KB
testcase_14 WA -
testcase_15 AC 1,045 ms
162,364 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,101 ms
161,804 KB
testcase_19 WA -
testcase_20 AC 1,035 ms
159,640 KB
testcase_21 WA -
testcase_22 AC 1,056 ms
162,352 KB
testcase_23 AC 1,067 ms
162,216 KB
testcase_24 WA -
testcase_25 AC 1,069 ms
160,768 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1,322 ms
185,412 KB
testcase_29 AC 1,168 ms
184,576 KB
testcase_30 AC 1,202 ms
184,540 KB
testcase_31 WA -
testcase_32 AC 805 ms
147,592 KB
testcase_33 AC 823 ms
147,320 KB
testcase_34 WA -
testcase_35 AC 808 ms
147,592 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 403 ms
154,244 KB
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0