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 <iostream>
#include <vector>
using namespace std;
vector<int> g[200005];
long long int f[200005][45], d[200005];
void dfs(int x, int p) {
d[x] = p;
for (int w : g[x]) {
if (w == p) continue;
dfs(w, x);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
long long int n, l;
cin >> n >> l;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 1);
for (int i = 1; i <= n; i++) {
long long int x;
cin >> x;
f[i][0] = x;
for (int j = 1; j <= 41; j++) f[i][j] = 1;
}
int q;
cin >> q;
for (int jj = 0; jj < q; jj++) {
int w;
cin >> w;
if (w == 1) {
long long int x, z, y;
cin >> x >> z >> y;
while (z >= 0) {
f[x][z] = f[x][z] * y % l;
x = d[x];
z--;
}
}
else {
long long int x, z = 0, res = 1;
cin >> x;
while (1) {
if (z == 41) break;
if (x == 1) {
res = res * f[x][z] % l;
break;
}
res = res * f[x][z] % l * f[x][z + 1] % l;
z++;
x = d[x];
}
cout << res << '\n';
}
}
}
# | 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... |