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;
int main(){
int N;
cin >> N;
vector<vector<int>> E(N);
for (int i = 0; i < N - 1; i++){
int X, Y;
cin >> X >> Y;
}
int M;
cin >> M;
vector<int> A(M), B(M), C(M);
for (int i = 0; i < M; i++){
cin >> A[i] >> B[i] >> C[i];
if (A[i] > B[i]){
swap(A[i], B[i]);
}
A[i]--;
}
vector<vector<int>> R(N + 1);
for (int i = 0; i < M; i++){
R[B[i]].push_back(i);
}
vector<int> dp(N + 1, 0);
for (int i = 1; i <= N; i++){
dp[i] = dp[i - 1];
for (int j : R[i]){
dp[i] = max(dp[i], dp[A[j]] + C[j]);
}
}
cout << dp[N] << endl;
}
# | 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... |