結果
| 問題 |
No.1054 Union add query
|
| コンテスト | |
| ユーザー |
hs0319boy
|
| 提出日時 | 2020-05-15 22:28:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,639 bytes |
| コンパイル時間 | 1,490 ms |
| コンパイル使用メモリ | 174,976 KB |
| 実行使用メモリ | 13,760 KB |
| 最終ジャッジ日時 | 2024-09-19 11:21:01 |
| 合計ジャッジ時間 | 5,876 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | TLE * 1 -- * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;
vin par(200050);
vin deep(200050);
void init(int n);
int root(int x);
void unite(int x,int y);
bool same(int x,int y);
int main(){
int n,q;cin>>n>>q;
queue<ll> que;
init(n);
vll wei(n+1,0);
rep(i,q){
int t,a,b;
scanf("%ld %ld %ld",&t,&a,&b);
if(t==1)unite(a,b);
if(t==2){
rep(i,n){
if(same(i+1,a))wei[i+1]+=b;
}
}
if(t==3)que.push(wei[a]);
}
while(que.size()){
printf("%ld\n",que.front());
que.pop();
}
}
void init(int n){
rep(i,n+1){
par[i]=i;
deep[i]=0;
}
}
int root(int x){
if(par[x]==x)return x;
else return par[x]=root(par[x]);
}
void unite(int x,int y){
x=root(x);
y=root(y);
if(x==y)return;
if(deep[x]<deep[y])par[x]=y;
else{
par[y]=x;
if(deep[x]==deep[y])deep[x]++;
}
}
bool same(int x,int y){
return root(x)==root(y);
}
hs0319boy