CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:andreibe
Submission time:2021-10-14 20:27:44 +0300
Language:C++11
Status:READY
Result:25
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED15
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.55 s2, 3details
#30.01 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:35:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (size_t i = 0; i < n+1; i++)
                            ~~^~~~~

Code

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

vector<pair<int,int>> puu[5001];
int kayty[5001];

long long total = 0;

void count(int index, int min) {
    vector<pair<int,int>> naapurit = puu[index];
    kayty[index] = 1;
    for (pair<int, int> pair : naapurit) {
        if (!kayty[pair.first]) {
            int val = std::min(min, pair.second);
            total += val;
            count(pair.first, val);
        }
    }
}
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n-1; i++)
    {
        int a;
        int b;
        int x;
        cin >> a >> b >> x;
        puu[a].push_back(pair<int,int>(b, x));
        puu[b].push_back(pair<int,int>(a, x));
        for (size_t i = 0; i < n+1; i++)
        {
            kayty[i] = 0;
        }
        count(a, x);
    }
    cout << total;
}

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: 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)