結果
問題 | No.1641 Tree Xor Query |
ユーザー | momoyuu |
提出日時 | 2022-08-03 02:42:10 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,025 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 628,924 KB |
最終ジャッジ日時 | 2024-07-23 20:45:16 |
合計ジャッジ時間 | 7,596 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | AC | 39 ms
52,876 KB |
testcase_02 | AC | 39 ms
53,920 KB |
testcase_03 | AC | 41 ms
53,952 KB |
testcase_04 | AC | 51 ms
62,724 KB |
testcase_05 | AC | 48 ms
61,700 KB |
testcase_06 | AC | 47 ms
62,116 KB |
testcase_07 | AC | 40 ms
53,484 KB |
testcase_08 | AC | 40 ms
53,184 KB |
testcase_09 | AC | 40 ms
53,400 KB |
testcase_10 | AC | 42 ms
53,584 KB |
testcase_11 | AC | 40 ms
54,360 KB |
testcase_12 | AC | 41 ms
54,428 KB |
testcase_13 | MLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
ソースコード
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()