CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:mooc.fi~486604
Submission time:2021-10-17 20:38:02 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.04 s2, 3details
#30.44 s3details

Compiler report

input/code.cpp: In function 'int isompi(int, int, int)':
input/code.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

Code

#include <iostream>
#include <vector>
#include <map>

 
using namespace std; 
int N;
vector<pair<int,int>> v[200001]; 
long long int sum;
bool tama=false; 
 
map<pair<int, int>, short int > juu; 
long long int globalsum=0; 
long long int valisum=0;
vector<pair<int,int> >pienemmat; 
map<pair<int,  int>, vector<pair<int, int>>> etsi; 
map<pair<int,  int>,  int> lukumaara; 
long long int summia; 
long long int stupidsum=0; 


int isompi(  int s, int e,  int target){
    for( auto u: v[s]){
       if(u.first==e){
            if( target==u.second){
                return 2; 
            }
            if( target>u.second){
                return 1; 
            }
            else{
                return 0; 
            }
       }
    }
}


int haku(int s, int e,int target){
 
    int ssumma=1; 
 
    for(auto u: v[s]){ 
        if(u.first!=e&&u.second==target){
            
            juu[{s, u.first}]=1;
            int uusi = haku(u.first, s, target);
            stupidsum+=uusi; 
            valisum+=globalsum*uusi; 
            globalsum+=uusi; 
            tama=true; }
        if(u.second<target){
            pienemmat.push_back({s, u.first});
        }
      
        if(u.first!=e&&u.second>target) ssumma+=haku(u.first, s, target);
}
return ssumma; 
}
 
 
int main()
{     
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    int a,b,c;
    long long int i; 
    sum=0; 
    cin>>N; 
    long long int di[N][3]; 
    for(i=0; i<N-1; i++){
        cin>>a>>b>>c;
        di[i][0]=c;
        di[i][1]=a;
        di[i][2]=b;
        v[a].push_back({b,c});
        v[b].push_back({a,c}); 
     
    }
    long long int vasen, oikea; 
    long long int kl0, kl1, kl2; 
    for(i=0; i<N-1; i++){
        stupidsum=0; 
        kl0 = di[i][0]; 
        kl1 = di[i][1];
        kl2 = di[i][2];
        if(juu[{kl2,kl1}]||juu[{kl1,kl2}])
            continue;
      
    

       if(lukumaara[{kl1, kl2}]){
           vasen=lukumaara[{kl1, kl2}];
           
           vector<pair<int,int>> temp2=etsi[{kl1, kl2}];
           for(auto er: temp2){
               if( er.first==kl1&&er.second==kl2) continue; 
               
               int kom = isompi(er.second, er.first, kl0);
               if(kom==2) {goto tamanain1; }
               if(kom) continue; 
               vasen+=haku(er.second , er.first, kl0);
           }
       }
       else{
        tamanain1:
        vasen=haku(kl1, kl2 , kl0);}

        if(lukumaara[{kl2, kl1}]){
           oikea=lukumaara[{kl2, kl1}];
           
           vector<pair<int, int>> temp1=etsi[{kl2, kl1}];
           for(auto er: temp1){
               if( er.first==kl2&&er.second==kl1) continue; 
               int kom = isompi(er.second, er.first, kl0);
               if(kom==2) {goto tamanain2; }
               if(kom) continue; 
               oikea+=haku(er.second, er.first, kl0)-1;
               
           }
        }

        else{
        tamanain2: 
        oikea=haku(kl2, kl1, kl0);}

        
        for( auto k: pienemmat){
            if(lukumaara[{k.first, k.second}]<vasen+oikea ){
            etsi[{k.first, k.second}]=pienemmat; 
            lukumaara[{k.first, k.second}]=vasen+oikea+stupidsum;}
        }
        
        pienemmat.clear();
        juu[{kl2, kl1}]=1;
        if(tama){
           
            valisum+=globalsum*vasen;
            globalsum+=vasen; 
            valisum+=globalsum*oikea;
            sum+=valisum*kl0;
            tama=false;
            globalsum=0; 
            valisum=0; 
            continue;
        }
       
        sum+= kl0*vasen*oikea;
        
      
    }
   
 
    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
88549

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
1077400798351882

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)