結果
| 問題 | 
                            No.1153 ねこちゃんゲーム
                             | 
                    
| コンテスト | |
| ユーザー | 
                             sasa8uyauya
                         | 
                    
| 提出日時 | 2025-07-20 02:52:26 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,844 bytes | 
| コンパイル時間 | 391 ms | 
| コンパイル使用メモリ | 82,108 KB | 
| 実行使用メモリ | 127,324 KB | 
| 最終ジャッジ日時 | 2025-07-20 02:52:56 | 
| 合計ジャッジ時間 | 27,913 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 3 WA * 2 RE * 35 | 
ソースコード
n,m=map(int,input().split())
a=list(map(int,input().split()))
e=[[] for i in range(n)]
for i in range(n-1):
  u,v=map(int,input().split())
  u-=1
  v-=1
  e[u]+=[v]
  e[v]+=[u]
v=[0]*n
p=[0]*n
u1=[0]*n
q=[0]
while len(q)>0:
  s=q[-1]
  if v[s]==0:
    v[s]=1
    for t in e[s]:
      if v[t]==0:
        p[t]=s
        q+=[t]
  else:
    c=[0]*(len(e[s])+1)
    for t in e[s]:
      if v[t]==0 and u1[t]<=len(e[s]):
        c[u1[t]]+=1
    for i in range(len(e[s])+1):
      if c[i]==0:
        u1[s]=i
        break
    v[s]=0
    q.pop()
u2=[0]*n
q=[0]
while len(q)>0:
  s=q[-1]
  if v[s]==0:
    v[s]=1
    c=[0]*(len(e[s])+1)
    for t in e[s]:
      if v[t]==0 and u1[t]<=len(e[s]):
        c[u1[t]]+=1
    if s!=0:
      if u2[s]<=len(e[s]):
        c[u2[s]]+=1
    for i in range(len(e[s])+1):
      if c[i]==0:
        g=i
        break
    for t in e[s]:
      if v[t]==0:
        if c[u1[t]]-1==0:
          u2[t]=u1[t]
        else:
          u2[t]=g
        q+=[t]
  else:
    v[s]=0
    q.pop()
f=[0]*n
for y in a:
  f[y-1]^=1
g=0
for s in range(n):
  if f[s]:
    c=[0]*(len(e[s])+1)
    for t in e[s]:
      if v[t]==0 and u1[t]<=len(e[s]):
        c[u1[t]]+=1
    if s!=0:
      if u2[s]<=len(e[s]):
        c[u2[s]]+=1
    for i in range(len(e[s])+1):
      if c[i]==0:
        g^=i
        break
if g==0:
  print(-1,-1)
  exit()
for s in range(n):
  if f[s]:
    c=[0]*(len(e[s])+1)
    for t in e[s]:
      if v[t]==0 and u1[t]<=len(e[s]):
        c[u1[t]]+=1
    if s!=0:
      if u2[s]<=len(e[s]):
        c[u2[s]]+=1
    for i in range(len(e[s])+1):
      if c[i]==0:
        g^=i
        for t in e[s]:
          if p[s]!=t:
            if g^u1[t]==0:
              print(a.index(s+1)+1,t+1)
              exit()
          elif s!=0:
            if g^u2[s]==0:
              print(a.index(s+1)+1,t+1)
              exit()
            
            
            
        
            
sasa8uyauya