CSES - Datatähti 2022 alku - Results
Submission details
Task:Tietoverkko
Sender:jusola
Submission time:2021-10-12 20:01:21 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.02 s1, 2, 3details
#20.01 s2, 3details
#30.01 s3details

Code

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;


void s2(int ov, int v, vector<pair<int, int>> *g, vector<pair<int, int>> &cr, int cm, int &res, vector<int> &vis2) {
    for (auto p: g[v]) {
        int u = p.first;
        int sp = p.second;
        if(find(vis2.begin(), vis2.end(), u) == vis2.end() && v != u && ov != u){
            if (find(cr.begin(), cr.end(), pair<int,int>(u,ov)) == cr.end() && find(cr.begin(), cr.end(), pair<int,int>(ov,u)) == cr.end()){
                if (cm == -1) cm = sp;
                if (sp < cm){
                    res += sp;
                }else{
                    res += cm;
                }
                cr.push_back({ov, u});
                
                //cout << "route: " << ov << " to " << u << " via " << v << " ls " << sp << " cm: " << cm << " total: " << res <<"\n";
            }
            vis2.push_back(u);
            
            if (sp < cm){
                s2(ov, u, g, cr, sp, res, vis2);
            }else{
                s2(ov, u, g, cr, cm, res, vis2);
            }
        }
    }
}


void s(int v, vector<pair<int, int>> *g, vector<pair<int, int>> &cr, int &res, vector<int> &vis){
    vector<int> vis2;
    s2(v, v, g, cr, -1, res, vis2);
    for (auto p: g[v]) {
        int u = p.first;
        if(find(vis.begin(), vis.end(), u) == vis.end()){
            vis.push_back(u);
            s(u, g, cr, res, vis);
        }
    }
}

int main() {
    vector<pair<int, int>> g[101];
    vector<pair<int, int>> cr;
    vector<int> vis;
    int n, res=0;
    cin >> n;

    for(int i=0; i<(n-1); i++){
        int a,b,sp;
        cin >> a >> b >> sp;
        g[a].push_back({b,sp});
        g[b].push_back({a,sp});
    }

    s(1, g, cr, res, vis);

    cout << res;

    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
107915

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)

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)