結果
| 問題 |
No.2342 Triple Tree Query (Hard)
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2023-04-08 18:29:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,953 bytes |
| コンパイル時間 | 2,162 ms |
| コンパイル使用メモリ | 179,364 KB |
| 実行使用メモリ | 18,724 KB |
| 最終ジャッジ日時 | 2024-12-28 12:25:03 |
| 合計ジャッジ時間 | 18,958 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
int N, Q;
cin >> N >> Q;
vector<vector<int>> E(N);
for (int i = 0; i < N - 1; i++){
int A, B;
cin >> A >> B;
A--;
B--;
E[A].push_back(B);
E[B].push_back(A);
}
vector<long long> X(N);
for (int i = 0; i < N; i++){
cin >> X[i];
}
vector<int> p(N, -1);
vector<vector<int>> c(N);
vector<int> d(N, 0);
queue<int> q;
q.push(0);
while (!q.empty()){
int v = q.front();
q.pop();
for (int w : E[v]){
if (w != p[v]){
p[w] = v;
c[v].push_back(w);
d[w] = d[v] + 1;
q.push(w);
}
}
}
for (int i = 0; i < Q; i++){
int T;
cin >> T;
if (T == 1){
int U, V;
long long C, D;
cin >> U >> V >> C >> D;
U--;
V--;
while (true){
if (U == V){
X[U] = (X[U] * C + D) % MOD;
break;
}
if (d[U] > d[V]){
swap(U, V);
}
X[V] = (X[V] * C + D) % MOD;
V = p[V];
}
}
if (T == 2){
int V;
long long C, D;
cin >> V >> C >> D;
V--;
auto dfs = [&](auto dfs, int v) -> void {
X[v] = (X[v] * C + D) % MOD;
for (int w : c[v]){
dfs(dfs, w);
}
};
dfs(dfs, V);
}
if (T == 3){
int V, K;
long long C, D;
cin >> V >> K >> C >> D;
V--;
vector<int> d2(N, -1);
d2[V] = 0;
queue<int> q;
q.push(V);
while (!q.empty()){
int v = q.front();
q.pop();
for (int w : E[v]){
if (d2[w] == -1){
d2[w] = d2[v] + 1;
q.push(w);
}
}
}
for (int j = 0; j < N; j++){
if (d2[j] <= K){
X[j] = (X[j] * C + D) % MOD;
}
}
}
if (T == 4){
int V;
cin >> V;
V--;
cout << X[V] << endl;
}
}
}
SSRS