CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:LiminalAlien
Submission time:2021-10-11 17:37:00 +0300
Language:C++11
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2--2, 3details
#3--3details

Code

using namespace std;
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

#define ll long long

ll e[200001];
ll p[200001];
map<pair<ll, ll>, ll> m;

ll haku(ll a, ll b)
{
	if (m.count({ a,b }))return m[{a, b}];
	if (m.count({ b,a }))return m[{b, a}];
	if (e[b] > e[a])
	{
		ll x = haku(p[b], b);
		ll y = min(x, haku(a, p[b]));
		m[{a, b}] = y;
		return y;
	}
	else
	{
		ll x = haku(p[a], b);
		ll y = min(x, haku(a, p[a]));
		m[{a, b}] = y;
		return y;
	}
}

int main()
{
	ll n;
	cin >> n;
	e[1] = 1;
	for (ll i = 1; i < n; i++)
	{
		ll a, b, x;
		cin >> a >> b >> x;
		e[b] = e[a] + 1;
		p[b] = a;
		m[{a, b}] = x;
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= n; j++)
		{
			if (i != j)haku(i, j);
		}
	}
	for (auto i : m)ans += i.second;
	cout << ans;
}

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:

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

correct output
1103702320243776

user output
(empty)

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)