#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
const int N = 2e5;
long long h[N+5];
int n, l;
vector<int> adj[N+5];
bool vis[N+5][45];
void dfs (int u, int prv, long long w, int dst) {
if (dst < 0) return;
h[u] *= w;
h[u] %= l;
//cerr << u << " lalala " << h[u] << endl;
for (int v : adj[u]) {
if (v==prv) continue;
dfs(v, u, w, dst-1);
}
}
void dfs4 (int u, int prv, long long w, int dst) {
if (dst < 0) return;
if (vis[u][dst]) return;
vis[u][dst] = true;
h[u] *= w;
h[u] %= l;
//cerr << u << " lalala " << h[u] << endl;
for (int v : adj[u]) {
if (v==prv) continue;
dfs4(v, u, w, dst-1);
}
}
int lst[N+5];
int sqr;
int mul (ll a, ll b) {
int res = (a*b) % l;
return res;
}
long long ht[N+5];
void dfs2 (int u, int prv, long long w, int dst) {
ht[u] = mul(ht[u], w);
if (dst == 0) return;
//cerr << u << " lalala " << h[u] << endl;
if (dst==1 && adj[u].size() < sqr) {
for (int v : adj[u]) {
if (v==prv) continue;
dfs2(v, u, w, dst-1);
}
}
}
void sub2() {
int q; cin>>q;
sqr = sqrt(n);
for(int i=1; i<=n; i++) {
ht[i] = 1;
}
for(int tm = 1; tm <= q; tm++) {
int tp;
cin >> tp;
if (tp == 1) {
int x, d, w;
cin >> x >> d >> w;
if (d == 0) h[x] = mul(h[x], w);
else dfs2(x, 0, w, d);
} else {
int x;
cin >> x;
ll res = mul(h[x], ht[x]);
if (adj[x].size() < sqr) {
for (int u : adj[x]) {
res = mul(res, ht[u]);
}
}
cout << res << endl;
}
}
}
void sub4() {
int q; cin>>q;
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int x, d, w;
cin >> x >> d >> w;
dfs4(x, 0, w, d);
} else {
int x;
cin >> x;
cout << h[x] << endl;
}
}
}
void sub1() {
int q; cin>>q;
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int x, d, w;
cin >> x >> d >> w;
dfs(x, 0, w, d);
} else {
int x;
cin >> x;
cout << h[x] << endl;
}
}
}
signed main () {
int t=1;
//scanf("%d", &t);
while(t--) {
cin >> n >> l;
for(int i=1; i<n; i++) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
for (int i=1; i<=n; i++) {
cin >> h[i];
}
if (n <= 1000) sub1();
else sub2();
}
}
Compilation message
sprinkler.cpp: In function 'void dfs2(int, int, long long int, int)':
sprinkler.cpp:55:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | if (dst==1 && adj[u].size() < sqr) {
| ~~~~~~~~~~~~~~^~~~~
sprinkler.cpp: In function 'void sub2()':
sprinkler.cpp:81:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
81 | if (adj[x].size() < sqr) {
| ~~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
3 ms |
5012 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5088 KB |
Output is correct |
5 |
Correct |
6 ms |
4996 KB |
Output is correct |
6 |
Correct |
8 ms |
5020 KB |
Output is correct |
7 |
Correct |
8 ms |
5076 KB |
Output is correct |
8 |
Correct |
8 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5012 KB |
Output is correct |
12 |
Correct |
5 ms |
5024 KB |
Output is correct |
13 |
Correct |
5 ms |
4948 KB |
Output is correct |
14 |
Correct |
5 ms |
5032 KB |
Output is correct |
15 |
Correct |
5 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
5020 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
5 ms |
5012 KB |
Output is correct |
21 |
Correct |
4 ms |
5012 KB |
Output is correct |
22 |
Correct |
4 ms |
5012 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
4964 KB |
Output is correct |
26 |
Correct |
4 ms |
4948 KB |
Output is correct |
27 |
Correct |
4 ms |
5016 KB |
Output is correct |
28 |
Correct |
4 ms |
5016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Incorrect |
949 ms |
18516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Incorrect |
949 ms |
18516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4928 KB |
Output is correct |
2 |
Incorrect |
891 ms |
17784 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
877 ms |
18504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
3 ms |
5012 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5088 KB |
Output is correct |
5 |
Correct |
6 ms |
4996 KB |
Output is correct |
6 |
Correct |
8 ms |
5020 KB |
Output is correct |
7 |
Correct |
8 ms |
5076 KB |
Output is correct |
8 |
Correct |
8 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5012 KB |
Output is correct |
12 |
Correct |
5 ms |
5024 KB |
Output is correct |
13 |
Correct |
5 ms |
4948 KB |
Output is correct |
14 |
Correct |
5 ms |
5032 KB |
Output is correct |
15 |
Correct |
5 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
5020 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
5 ms |
5012 KB |
Output is correct |
21 |
Correct |
4 ms |
5012 KB |
Output is correct |
22 |
Correct |
4 ms |
5012 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
4964 KB |
Output is correct |
26 |
Correct |
4 ms |
4948 KB |
Output is correct |
27 |
Correct |
4 ms |
5016 KB |
Output is correct |
28 |
Correct |
4 ms |
5016 KB |
Output is correct |
29 |
Correct |
3 ms |
5012 KB |
Output is correct |
30 |
Incorrect |
949 ms |
18516 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |