Task: | Tietoverkko |
Sender: | hltk |
Submission time: | 2021-10-04 00:11:30 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
#2 | WRONG ANSWER | 0.01 s | 2, 3 | details |
#3 | WRONG ANSWER | 0.27 s | 3 | details |
Code
#include <iostream> #include <vector> using namespace std; const int N = 200001; int n; long r; vector<pair<int, int>> g[N]; int dfs(int s, int e) { int sz = 1; for (auto [u, w] : g[s]) { if (u != e) { int z = dfs(u, s); r += 1ll * z * (n - z) * w; sz += z; } } return sz; } int main() { cin >> n; for (int i = 0; i < n - 1; ++i) { int a, b, x; cin >> a >> b >> x; g[a].emplace_back(b, x); g[b].emplace_back(a, x); } dfs(1, 1); cout << r / 2 << endl; }
Test details
Test 1
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
100 1 2 74 1 3 100 2 4 50 3 5 40 ... |
correct output |
---|
88687 |
user output |
---|
1070664 |
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 |
---|
50723392971564305 |
Test 3
Group: 3
Verdict: WRONG ANSWER
input |
---|
200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1080549209850010931 |
user output |
---|
-2118890155620361669 |