結果
| 問題 |
No.1641 Tree Xor Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-17 16:47:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 625 ms / 5,000 ms |
| コード長 | 597 bytes |
| コンパイル時間 | 436 ms |
| コンパイル使用メモリ | 82,436 KB |
| 実行使用メモリ | 206,552 KB |
| 最終ジャッジ日時 | 2024-10-10 15:14:31 |
| 合計ジャッジ時間 | 4,615 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
import sys
sys.setrecursionlimit(10**9)
N,Q=map(int,input().split())
C=list(map(int,input().split()))
G=[[] for _ in range(N)]
for i in range(N-1):
a,b=map(lambda x:int(x)-1,input().split())
G[a].append(b)
G[b].append(a)
seen=[False]*N
par=[-1]*N
subtree_xor=C
def dfs(G,v,p=-1):
seen[v]=True
par[v]=p
for nextv in G[v]:
if nextv!=p:
dfs(G,nextv,v)
for c in G[v]:
if c!=p:
subtree_xor[v]^=subtree_xor[c]
dfs(G,0)
for _ in range(Q):
t,x,y=map(int,input().split())
x-=1
if t==1:
while x!=-1:
subtree_xor[x]^=y
x=par[x]
else:
print(C[x])