Submission #419589

#TimeUsernameProblemLanguageResultExecution timeMemory
419589tengiz05Election Campaign (JOI15_election_campaign)C++17
10 / 100
89 ms10552 KiB
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n; std::vector<std::vector<int>> e(n); for (int i = 0; i < n - 1; i++) { int u, v; std::cin >> u >> v; u--; v--; e[u].push_back(v); e[v].push_back(u); } std::cin >> m; std::vector<std::vector<std::pair<int, int>>> q(n + 1); for (int i = 0; i < m; i++) { int u, v, c; std::cin >> u >> v >> c; if (u > v) std::swap(u, v); q[v].emplace_back(u, c); } std::vector<int> dp(n + 1); for (int i = 1; i <= n; i++) { dp[i] = dp[i - 1]; for (auto [j, c] : q[i]) { dp[i] = std::max(dp[i], dp[j - 1] + c); } } std::cout << dp[n] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...