# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
109199 | dupreez | Election Campaign (JOI15_election_campaign) | C++14 | 73 ms | 2168 KiB |
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 <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 (stderr)
# | 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... |