#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <deque>
#include <climits>
#define scanf scanf_s
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 5010;
ll n, m,dp[N];
vector<pos> g[N];
int main() {
cin >> n;
for (int i = 0; i < n - 1; i++) { int v1, v2; cin >> v1 >> v2; }
cin >> m;
while (m--) {
int v1, v2, v3; cin >> v1 >> v2 >> v3;
if (v2 < v1)swap(v1, v2);
g[v1].pb(mk(v3, v2+1));
}
for (int i = 1; i <= n; i++) {
dp[i] = max(dp[i], dp[i - 1]);
for (int j = 0; j < g[i].size(); j++)dp[g[i][j].second] = max(dp[g[i][j].second], dp[i] + g[i][j].first);
}
ll ans = 0;
for (int i = 1; i <= n+1; i++)ans = max(ans, dp[i]);
cout << ans << endl;
return 0;
}
Compilation message
election_campaign.cpp: In function 'int main()':
election_campaign.cpp:32:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < g[i].size(); j++)dp[g[i][j].second] = max(dp[g[i][j].second], dp[i] + g[i][j].first);
~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
4 |
Runtime error |
70 ms |
2168 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
4 |
Runtime error |
70 ms |
2168 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
73 ms |
2160 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |