#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define f first
#define s second
#define pii pair <int,int>
#define en '\n'
void boos() {
ios_base :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 4e5 + 100;
vector <int> g[N];
pii c[N];
ll a[N],L;
int d[N][50];
int n;
void dfs(int v,int p,int k) {
for(auto to : g[v]) {
d[to][k - 1] = min(d[to][k - 1],d[v][k]);
if(to == p)continue;
dfs(to,v,k);
}
}
void solve() {
cin >> n >> L;
for(int i = 1;i <= n;i++) {
for(int j = 0;j <= 40;j++)d[i][j] = n + 1;
}
for(int i = 1;i < n;i++) {
int x,y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for(int i = 1;i <= n;i++)cin >> a[i];
int q;
cin >> q;
int l = 1;
for(int i = 1;i <= q;i++) {
cin >> c[i].f;
if(c[i].f == 1) {
int x,dist;
ll w;
cin >> x >> dist >> w;
for(int j = dist;j >= 0;j--)d[x][j] = min(d[x][j],i);
}else cin >> c[i].s;
}
for(int i = 40;i >= 1;i--)dfs(1,-1,i);
for(int i = 1;i <= n;i++) {
for(int j = 39;j >= 0;j--) {
d[i][j] = min(d[i][j],d[i][j + 1]);
}
}
for(int i = 1;i <= q;i++) {
if(c[i].f == 2) {
if(d[c[i].s][0] <= i) {
cout << 0 << en;
}else {
cout << a[c[i].s] << en;
}
}
}
}
int main() {
boos();
int ttt;
ttt = 1;
while(ttt--) {
solve();
}
}
Compilation message
sprinkler.cpp: In function 'void solve()':
sprinkler.cpp:42:6: warning: unused variable 'l' [-Wunused-variable]
42 | int l = 1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
2135 ms |
75640 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |