CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:hltk
Submission time:2021-10-04 00:11:30 +0300
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s2, 3details
#30.27 s3details

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:

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:

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:

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

correct output
1080549209850010931

user output
-2118890155620361669