結果

問題 No.1153 ねこちゃんゲーム
ユーザー mkawa2mkawa2
提出日時 2021-10-13 00:50:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,289 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 80,236 KB
実行使用メモリ 194,520 KB
最終ジャッジ日時 2023-10-17 15:01:57
合計ジャッジ時間 48,082 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,360 KB
testcase_01 AC 37 ms
52,316 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 70 ms
73,344 KB
testcase_06 WA -
testcase_07 AC 989 ms
169,892 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 963 ms
171,292 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 971 ms
171,204 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1,218 ms
194,092 KB
testcase_29 WA -
testcase_30 AC 943 ms
194,172 KB
testcase_31 AC 976 ms
194,520 KB
testcase_32 AC 653 ms
149,440 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

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

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

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])

# 上から更新
gg = [-1]*n
for u in uu:
    cs = e()
    # ↓変数注意
    for v in to[u]:
        rdp[v] = cs
        cs = op(cs, dp[v])
    cs = e() if u == root else 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
            break
# print(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 g ^ gg[a] ^ rdp[a] == 0:
        print(i+1, par[a]+1)
        exit()
0