結果
| 問題 |
No.1054 Union add query
|
| コンテスト | |
| ユーザー |
mot
|
| 提出日時 | 2020-05-15 22:07:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,499 bytes |
| コンパイル時間 | 769 ms |
| コンパイル使用メモリ | 84,604 KB |
| 実行使用メモリ | 20,680 KB |
| 最終ジャッジ日時 | 2024-09-19 10:41:47 |
| 合計ジャッジ時間 | 4,430 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d %d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
36 | scanf("%d %d %d", &T[i], &A[i], &B[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;
int par[500005], siz[500005], num[500005];
int root(int x){
while(x!=par[x]) x = par[x];
return x;
}
int main() {
int N, Q;
scanf("%d %d", &N, &Q);
int T[Q], A[Q], B[Q];
for(int i=0;i<Q;++i){
scanf("%d %d %d", &T[i], &A[i], &B[i]);
A[i]--;
if(T[i]==1){
B[i]--;
}
}
for(int i=0;i<N;++i){
par[i] = i;
siz[i] = 1;
num[i] = 0;
}
int roota, rootb;
for(int i=0;i<Q;++i){
if(T[i]==1){
roota = root(A[i]);
rootb = root(B[i]);
if(roota != rootb){
if(siz[roota] > siz[rootb]) swap(roota, rootb);
par[roota] = rootb;
siz[rootb] += siz[roota];
}
}
if(T[i]==2){
roota = root(A[i]);
for(int j=0;j<N;++j){
if(roota == root(j)){
num[j] += B[i];
}
}
}
if(T[i]==3){
printf("%d\n", num[A[i]]);
}
}
}
mot