結果

問題 No.1054 Union add query
ユーザー Jalil Sami SajidJalil Sami Sajid
提出日時 2020-05-16 08:06:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 913 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 181,580 KB
実行使用メモリ 122,324 KB
最終ジャッジ日時 2023-10-21 19:21:32
合計ジャッジ時間 8,221 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,696 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<int> 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;
}
0