結果
問題 | No.1054 Union add query |
ユーザー |
![]() |
提出日時 | 2020-05-15 22:10:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 743 bytes |
コンパイル時間 | 1,608 ms |
コンパイル使用メモリ | 171,460 KB |
実行使用メモリ | 814,008 KB |
最終ジャッジ日時 | 2024-09-19 10:44:36 |
合計ジャッジ時間 | 3,963 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 MLE * 1 -- * 1 |
other | -- * 8 |
ソースコード
#include <bits/stdc++.h>#define rep(i, a, n) for(int i = a; i < n; i++)using namespace std;using ll = long long;using P = pair<int, int>;vector<int> to[500005];vector<int> ans;int b;void dfs(int v, int p = -1){for(auto u : to[v]){if(u == p) continue;ans[u] += b;dfs(u, v);}}int main(){int n, q;cin >> n >> q;ans.resize(n);rep(i, 0, q){int t, a;cin >> t >> a >> b;a--;if(t == 1){b--;to[a].push_back(b);to[b].push_back(a);}else if(t == 2){ans[a] += b;dfs(a, -1);}else{cout << ans[a] << endl;}}return 0;}