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

Code

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

using namespace std;

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

int 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 < 1001; i++)
        {
            kayty[i] = 0;
        }
        count(a, x);
    }
    cout << total;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

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)

Error:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

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)

Error:
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc