結果
問題 |
No.1054 Union add query
|
ユーザー |
|
提出日時 | 2020-05-16 08:18:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 919 bytes |
コンパイル時間 | 1,875 ms |
コンパイル使用メモリ | 182,296 KB |
実行使用メモリ | 404,096 KB |
最終ジャッジ日時 | 2024-09-21 21:01:41 |
合計ジャッジ時間 | 7,946 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | WA * 2 TLE * 1 -- * 5 |
ソースコード
#include <bits/stdc++.h> #define endl '\n' using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t,k; cin>>t>>k; vector<long long> scor(t+1,0); map<int,set<int>> maya; vector<int> fink(t+1,0); int jdid=0; while(k--){ int a,b,c; cin>>a>>b>>c; if(a==1){ if (fink[b]==0 && fink[c]==0){ int m=jdid+1; fink[b]=m; fink[c]=m; maya[m]={b,c}; } else { int moul=((maya[fink[b]].size()>=maya[fink[c]].size())? b:c); int mach=((moul==b)? c:b); if (fink[mach]==0){ maya[fink[moul]].insert(mach); fink[mach]=fink[moul]; } else{ for(auto e:maya[fink[mach]]){ fink[e]=fink[moul]; maya[moul].insert(e); } } } } else if(a==2){ if (fink[b]==0){ fink[b]=++jdid; maya[fink[b]].insert(b); } for(auto e:maya[fink[b]]) scor[e]+=c; } else if(a==3){ cout<<scor[b]<<endl; } } return 0; }