#include <bits/stdc++.h>
using namespace std;
#define int long long
const int modulo = 1e9+7;
int DP[100001];
vector<pair<int,int>> transitions[100001];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin >> n;
for(int i=1;i<n;i++)cin>>m>>m;
cin >> m;
for(int i=1;i<=m;i++){
int a,b,c;cin>>a>>b>>c;
if(a>b)swap(a,b);
transitions[b].emplace_back(a-1,c);
}
for(int i=1;i<=n;i++){
DP[i] = DP[i-1];
for(auto&x:transitions[i])DP[i]=max(DP[i],x.second+DP[x.first]);
}
cout << DP[n] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
37 ms |
8496 KB |
Output is correct |
5 |
Correct |
33 ms |
8368 KB |
Output is correct |
6 |
Correct |
33 ms |
8456 KB |
Output is correct |
7 |
Correct |
36 ms |
8508 KB |
Output is correct |
8 |
Correct |
33 ms |
8528 KB |
Output is correct |
9 |
Correct |
37 ms |
8532 KB |
Output is correct |
10 |
Correct |
33 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
37 ms |
8496 KB |
Output is correct |
5 |
Correct |
33 ms |
8368 KB |
Output is correct |
6 |
Correct |
33 ms |
8456 KB |
Output is correct |
7 |
Correct |
36 ms |
8508 KB |
Output is correct |
8 |
Correct |
33 ms |
8528 KB |
Output is correct |
9 |
Correct |
37 ms |
8532 KB |
Output is correct |
10 |
Correct |
33 ms |
8528 KB |
Output is correct |
11 |
Correct |
5 ms |
3672 KB |
Output is correct |
12 |
Correct |
36 ms |
8692 KB |
Output is correct |
13 |
Correct |
43 ms |
8676 KB |
Output is correct |
14 |
Correct |
35 ms |
8800 KB |
Output is correct |
15 |
Correct |
42 ms |
8788 KB |
Output is correct |
16 |
Correct |
35 ms |
8780 KB |
Output is correct |
17 |
Correct |
35 ms |
8796 KB |
Output is correct |
18 |
Correct |
34 ms |
8788 KB |
Output is correct |
19 |
Correct |
35 ms |
8804 KB |
Output is correct |
20 |
Correct |
43 ms |
8680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
8564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2808 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |