#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,u,v,t,event,c,l;
ll a[200200];
ll kali,pulau,jarak;
vector<ll> adj[200200];
bool vis[200200];
ll dist[200200];
queue<ll> q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> l;
FOR(1,i,n-1) {
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
FOR(1,i,n) {
cin >> a[i];
}
cin >> t;
while(t--) {
cin >> event;
if(event == 1) {
cin >> pulau >> jarak >> kali;
q.push(pulau);
a[pulau] *= kali;
a[pulau] %= l;
vis[pulau] = true;
while(!q.empty()) {
ll x = q.front();
q.pop();
if(dist[x] == jarak) continue;
for(auto i : adj[x]) {
if(!vis[i]) {
dist[i] = dist[x] + 1;
vis[i] = true;
a[i] *= kali;
a[i] %= l;
q.push(i);
}
}
}
FOR(1,i,n) {
vis[i] = false;
dist[i] = 0;
}
// FOR(1,i,n) {
// cout << i << " : " << a[i] << endl;
// }
// cout << endl;
}
else {
cin >> c;
cout << a[c]%l << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4968 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5068 KB |
Output is correct |
5 |
Correct |
5 ms |
5092 KB |
Output is correct |
6 |
Correct |
7 ms |
5100 KB |
Output is correct |
7 |
Correct |
8 ms |
5100 KB |
Output is correct |
8 |
Correct |
8 ms |
5108 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5008 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
5024 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
2 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
1300 ms |
19080 KB |
Output is correct |
3 |
Execution timed out |
4054 ms |
15808 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
1300 ms |
19080 KB |
Output is correct |
3 |
Execution timed out |
4054 ms |
15808 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
1660 ms |
15460 KB |
Output is correct |
3 |
Execution timed out |
4043 ms |
14684 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
1671 ms |
18244 KB |
Output is correct |
3 |
Execution timed out |
4078 ms |
14836 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4968 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5068 KB |
Output is correct |
5 |
Correct |
5 ms |
5092 KB |
Output is correct |
6 |
Correct |
7 ms |
5100 KB |
Output is correct |
7 |
Correct |
8 ms |
5100 KB |
Output is correct |
8 |
Correct |
8 ms |
5108 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5008 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
5024 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
2 ms |
4948 KB |
Output is correct |
25 |
Correct |
2 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
1300 ms |
19080 KB |
Output is correct |
31 |
Execution timed out |
4054 ms |
15808 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |