CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko (Network)
Sender:EeliH
Submission time:2021-10-06 19:54:15
Language:C++11
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.47 s2, 3details
#30.25 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:50:9: warning: variable 'u' set but not used [-Wunused-but-set-variable]
     int u = 0;
         ^

Code

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

using namespace std;

vector<struct A> c;
vector<int> a[200000];
bool z[200000] = {false};
    
struct A {
    int a;
    int b;
    int x;
};

bool a_comp(struct A q, struct A b)
{
    return q.x < b.x;
}

int maara(int q, int pois)
{
    int m = z[q] ? 0 : 1;
    for(int naapuri: a[q]) {
        if(naapuri != pois) {
            m += maara(naapuri, q);
        }
    }
    return m;
}

int main()
{
    int n;
    cin >> n;

    for(int i = 0; i < n - 1; i++) {
        struct A b;
        cin >> b.a >> b.b >> b.x;
        c.push_back(b);
        a[b.a].push_back(b.b);
        a[b.b].push_back(b.a);
    }

    sort(c.begin(), c.end(), a_comp);

    uint64_t summa = 0;
    int h = 0;
    int u = 0;
    for(struct A i: c) {
        //cout << "A: " << i.a << " " << i.b << " " << i.x << endl;
        //cout << maara(i.a, i.b) << endl;
        /*for(int naapuri: a[i.a]) {

        }*/
        //if(u < i.x) {
            int r = (maara(i.a, i.b)) * i.x;
            if(r > 0) {
                summa += r;
            }
            u = i.x;
            z[i.a] = true;
        //}
        h++;
    }

    cout << summa << 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
278234

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
2692686401203

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)