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;
void dfs (ll u, ll par, ll w, ll dis, ll maxD) {
(ve[u] *= w) %= L;
if (dis == maxD) return;
for (ll v : adj[u]) {
if (v == par) continue;
dfs(v, u, w, dis+1, maxD);
}
}
int main () {
cin.tie(nullptr) -> sync_with_stdio(false);
ll n;
cin >> n >> L;
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;
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--;
dfs(u, u, w, 0, maxD);}
break;
case '2':
{ll u;
cin >> u;
u--;
cout << ve[u] << '\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... |