結果
問題 |
No.1054 Union add query
|
ユーザー |
|
提出日時 | 2025-10-14 03:04:41 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 620 bytes |
コンパイル時間 | 422 ms |
コンパイル使用メモリ | 82,828 KB |
実行使用メモリ | 228,116 KB |
最終ジャッジ日時 | 2025-10-14 03:04:46 |
合計ジャッジ時間 | 4,932 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 7 |
ソースコード
def aa(m): c=[] while m!=uf[m]: c.append(m) m=uf[m] for i in c: uf[i]=m return m n,q=map(int,input().split()) s=[[i] for i in range(n+1)] uf=[i for i in range(n+1)] x=[0]*(n+1) v=[0]*(n+1) for i in range(q): t,a,b=map(int,input().split()) if t==1: a,b=aa(a),aa(b) if len(s[a])<len(s[b]): c=[] for j in s[a]: v[j]-=x[b]-x[a] c.append(j) s[a]=[];uf[a]=b s[b]+=c else: c=[] for j in s[b]: v[j]-=x[a]-x[b] c.append(j) s[b]=[];uf[b]=a s[a]+=c elif t==2: x[aa(a)]+=b else: print(v[a]+x[aa(a)])