-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG_Path_Prefixes.cpp
More file actions
53 lines (42 loc) · 942 Bytes
/
G_Path_Prefixes.cpp
File metadata and controls
53 lines (42 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
vector<array<int, 3>> adj[N];
int dp[N];
vector<int> temp;
void dfs(int node, int sum, int sum2) {
dp[node] = upper_bound(temp.begin(), temp.end(), sum) - temp.begin();
for(auto &[ch, ai, bi] : adj[node]) {
temp.push_back(sum2 + bi);
dfs(ch, sum + ai, sum2 + bi);
temp.pop_back();
}
}
void YHTWH() {
int n;
cin >> n;
for(int i=0;i<=n;i++) {
adj[i].clear();
dp[i] = 0;
}
temp.clear();
for(int i=2;i<=n;i++) {
int p, a, b;
cin >> p >> a >> b;
adj[p].push_back({i, a, b});
}
dfs(1, 0, 0);
for(int i=2;i<=n;i++) cout << dp[i] << " "; cout << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int _;
cin >> _;
while (_-->0) {
YHTWH();
}
return 0;
}