Task: | Tietoverkko |
Sender: | MojoLake |
Submission time: | 2021-10-10 07:34:08 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 10 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | WRONG ANSWER | 0.47 s | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <iostream> #include <vector> using namespace std; vector<pair<int, int>> adj_list[200001]; int dfs(int c, int p, int min1){ int ans = 0; for(auto nei : adj_list[c]){ if(nei.second == p)continue; ans += min(min1, nei.first); ans += dfs(nei.second, c, min(min1, nei.first)); } return ans; } int main(){ int n; cin >> n; for(int i = 0; i < n - 1; ++i){ int a, b, x;; cin >> a >> b >> x; adj_list[a].push_back(make_pair(x, b)); adj_list[b].push_back(make_pair(x, a)); } int ans = 0; for(int i = 1; i <= n; ++i){ ans += dfs(i, 0, 1e9); } cout << ans/2; return 0; }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 74 1 3 100 2 4 50 3 5 40 ... |
correct output |
---|
88687 |
user output |
---|
88687 |
Test 2
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
5000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1103702320243776 |
user output |
---|
951870528 |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1080549209850010931 |
user output |
---|
(empty) |