CSES - DatatÃ¤hti 2022 alku - Results
 Task: Tietoverkko (Network) Sender: cowperso Submission time: 2021-10-09 09:06:17 Language: C++11 Status: READY Result: 0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#2ACCEPTED0.07 s2, 3details
#3--3details

### Code

```#include <iostream>
#include <vector>
#include <utility>
using namespace std;

static vector<vector<pair<uint64_t, uint64_t>>> puu;

static uint64_t hitaammat(uint64_t s, uint64_t e, uint64_t vert, uint64_t alk) {
uint64_t summa = 0;
for (auto seur : puu[s]) {
if (seur.first == e)
continue;
if (seur.second < vert)
continue;
uint64_t inc = 1;
if (seur.second == vert) {
if (seur.first < alk)
inc = 0;
}
summa += hitaammat(seur.first, s, vert, alk) + inc;
}
return summa;
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

uint64_t n;
cin >> n;

puu.reserve(n);

for (uint64_t i = 0; i < n - 1; ++i) {
uint64_t a, b, nopeus;
cin >> a >> b >> nopeus;
puu[a - 1].push_back({b - 1, nopeus});
puu[b - 1].push_back({a - 1, nopeus});
}

uint64_t summa = 0;
for (uint64_t i = 0; i < n; ++i) {
for (auto solmu : puu[i]) {
if (i > solmu.first)
continue;
summa += (hitaammat(i, solmu.first, solmu.second, solmu.first) + 1) * (hitaammat(solmu.first, i, solmu.second, i) + 1) * solmu.second;
}
}

//cout << hitaammat(1, 0, puu[0][0].second);
cout << summa << '\n';
}
```

### Test details

Group: 1, 2, 3

Verdict:

input
100
1 2 74
1 3 100
2 4 50
3 5 40
...

correct output
88687

user output
89897

#### Test 2

Group: 2, 3

Verdict: ACCEPTED

input
5000
1 2 613084013
1 3 832364259
2 4 411999902
3 5 989696303
...

correct output
1103702320243776

user output
1103702320243776

#### Test 3

Group: 3

Verdict:

input
200000
1 2 613084013
1 3 832364259
2 4 411999902
3 5 989696303
...

correct output
1080549209850010931

user output
(empty)