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 <bits/stdc++.h>
using namespace std;
const int LOG = 21;
const int MAX = 2e6 + 15;
int n, m, dp[MAX];
vector<pair<int, int>> queries[MAX];
int32_t main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i < n; i++){
int u, v; cin >> u >> v;
}
cin >> m;
while(m--){
int u, v, w; cin >> u >> v >> w;
if(u > v) swap(u, v);
queries[v].emplace_back(u, w);
}
for(int i = 1; i <= n; i++){
dp[i] = dp[i - 1];
for(auto [j, w] : queries[i])
dp[i] = max(dp[i], dp[j - 1] + w);
}
cout << dp[n] << '\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... |