結果
問題 | No.1641 Tree Xor Query |
ユーザー | momoyuu |
提出日時 | 2022-08-03 02:43:44 |
言語 | PyPy2 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,025 bytes |
コンパイル時間 | 1,717 ms |
コンパイル使用メモリ | 76,588 KB |
実行使用メモリ | 226,376 KB |
最終ジャッジ日時 | 2024-07-23 20:47:09 |
合計ジャッジ時間 | 5,596 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
ソースコード
def main(): import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline N,Q = map(int,input().split()) C = list(map(int,input().split())) def f(n): return int(n) - 1 ab = [list(map(f,input().split())) for _ in range(N-1)] # txy = [list(map(int,input().split())) for _ in range(Q)] e = [[] for _ in range(N)] for i in range(N-1): a,b = ab[i] e[a].append(b) e[b].append(a) sum = [0 for _ in range(N)] d = [[0,0] for _ in range(N)] l = [0 for _ in range(N)] def euler(n,k): d[n][0] = k l[n] = 1 now = k for i in e[n]: if l[i] == 1: continue qqq = euler(i,now+1) now = qqq d[n][1] = now + 1 return (now + 1) euler(0,0) import math def dfs(n): l[n] = 1 sum[n] = C[n] for i in e[n]: if l[i]: continue s = dfs(i) sum[n] ^= s return sum[n] q = math.floor(math.sqrt(Q)) nowq = 0 while True: for i in range(N): l[i] = 0 dfs(0) p = 1 txy = [] for i in range(q): nq = q * nowq + i if nq >= Q: p = 0 break txy.append(list(map(int,input().split()))) t,x,y = txy[i] if t == 1: continue x -= 1 s = sum[x] for j in range(i): nnq = q * nowq + j nt,nx,ny = txy[j] if nt == 2: continue nx -= 1 if d[x][0] <= d[nx][0] <= d[x][1]: s ^= ny print(s) if not p: break for i in range(q): nq = q * nowq + i t,x,y = txy[i] if t == 2: continue x -= 1 C[x] ^= y nowq += 1 if __name__ == '__main__': main()