結果
問題 |
No.1054 Union add query
|
ユーザー |
![]() |
提出日時 | 2020-05-16 22:42:29 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 921 bytes |
コンパイル時間 | 229 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 48,640 KB |
最終ジャッジ日時 | 2024-09-22 21:32:07 |
合計ジャッジ時間 | 10,998 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 RE * 2 |
ソースコード
from sys import setrecursionlimit from sys import stdin def find(parent, amount, i): t = parent[i] if t < 0: return i, 0 t, a = find(parent, amount, t) parent[i] = t amount[i] += a return t, amount[i] def unite(parent, amount, i, j): i, _ = find(parent, amount, i) j, _ = find(parent, amount, j) if i == j: return parent[j] += parent[i] parent[i] = j amount[i] -= amount[j] setrecursionlimit(10 ** 5) readline = stdin.readline N, Q = map(int, readline().split()) parent = [-1] * (N + 1) amount = [0] * (N + 1) result = [] for _ in range(Q): T, A, B = map(int, readline().split()) if T == 1: unite(parent, amount, A, B) elif T == 2: j, _ = find(parent, amount, A) amount[j] += B elif T == 3: j, a = find(parent, amount, A) result.append(amount[j] + a) print('\n'.join(str(v) for v in result))