This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
const ll MAXN = 2E5+16;
vll adj[MAXN];
ll L;
vll ve;
ll par[MAXN];
ll src[MAXN];
void dfs (ll u, ll par) {
::par[u] = par;
for (ll v : adj[u]) {
if (v == par) continue;
dfs(v, u);
}
}
int main () {
cin.tie(nullptr) -> sync_with_stdio(false);
ll n;
cin >> n >> L;
fill(src, src+n, 1);
for (ll i = 1; i < n; i++) {
ll u, v;
cin >> u >> v;
u--; v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
ve = vll(n);
for (ll &i : ve) cin >> i;
dfs(0, 0);
ll Q;
cin >> Q;
for (ll q = 0; q < Q; q++) {
char type;
cin >> type;
switch (type) {
case '1':
{ll u, maxD, w;
cin >> u >> maxD >> w;
u--;
if (maxD == 0) {
(ve[u] *= w) %= L;
} else {
if (u) (ve[par[u]] *= w) %= L;
(ve[u] *= w) %= L;
(src[u] *= w) %= L;
}
break;}
case '2':
{ll u;
cin >> u;
u--;
ll ans = ve[u];
if (u) (ans *= src[par[u]]) %= L;
cout << ans << '\n';
break;}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |