CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:mooc.fi~486604
Submission time:2021-10-05 11:59:47 +0300
Language:C++11
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.07 s2, 3details
#30.24 s3details

Code

// C++ implementation to count the
// number of ways to partition the
// string such that each partition
// have same number of distinct
// characters in the string
 
#include <bits/stdc++.h>

using namespace std; 
int N;
vector<pair<int,int>> v[200000];
long long int sum;

void haku(int s, int e, int target){
    if(e!=0)
    sum+=target; 
    
    for(auto u: v[s]){
        if(u.first!=e&&u.second>=target) haku(u.first, s, target);
    }


}

void syvahaku(int r, int e, int weight){
    if(e!=0)
    haku(r, 0, weight );
    for(auto u: v[r]){
        if(u.first!=e) syvahaku(u.first, r, u.second);
    }
}



   
int main()
{
    long long int i, a,b,c;
    sum=0; 

    cin>>N; 
    
    for(i=0; i<N-1; i++){
        cin>>a>>b>>c;
        v[a].push_back({b,c});
        v[b].push_back({a,c});
    }
    syvahaku(v[1][0].first, 0, v[1][0].second);
    cout<<sum;
  
    return 0;
}

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
46013

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
213420894492286

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