254412026-02-20 09:46:07KevinKaktusz túra (45 pont)cpp17Wrong answer 17/4524ms5428 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll, ll>;

ll total=0;
vector<map<ll, ll>> graph;
vector<ll> check;
vector<ll> parent;
vector<ll> dis;

void korkereses(ll p){
    check[p]++;
    for (auto& [child, cost]:graph[p]){
        if (parent[p]==child) continue;
        if (check[child]==1){
            check[p]++;
            total-=graph[child][p];
            graph[child][p]*=-1;
            graph[p][child]*=-1;
            ll x=p;
            while (x!=child){
                total-=graph[x][parent[x]];
                graph[x][parent[x]]*=-1;
                graph[parent[x]][x]*=-1;
                x=parent[x];
                check[x]++;
            }
        }
        if (check[child]==0){
            parent[child]=p;
            korkereses(child);
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n, m; cin >> n >> m;
    graph.resize(m);
    check.resize(n, false);
    parent.resize(n, -1);
    dis.resize(n, -1);
    for (ll i=0; i<m; i++){
        ll a, b, c; cin >> a >> b >> c; a--; b--;
        total+=2*c;
        graph[a][b]=c;
        graph[b][a]=c;
    }
    korkereses(0);

    priority_queue<pll> pq;
    pq.push({0, 0});
    ll leghosszabbut=0;
    while (pq.size()>0){
        ll currDis=pq.top().first, currId=pq.top().second;
        pq.pop();
        if (currDis<=dis[currId]) continue;
        dis[currId]=currDis;
        leghosszabbut=max(leghosszabbut, currDis);
        for (auto& [child, cost]:graph[currId]){
            if (parent[currId]!=child) pq.push({currDis+cost, child});
        }
    }
    cout << total-leghosszabbut;
}
SubtaskSumTestVerdictTimeMemory
base17/45
1Accepted0/01ms316 KiB
2Wrong answer0/021ms5428 KiB
3Runtime error0/22ms620 KiB
4Runtime error0/22ms500 KiB
5Runtime error0/21ms564 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms508 KiB
8Accepted2/21ms540 KiB
9Accepted2/21ms316 KiB
10Accepted2/21ms316 KiB
11Wrong answer0/21ms316 KiB
12Runtime error0/38ms3636 KiB
13Runtime error0/34ms2356 KiB
14Runtime error0/38ms3384 KiB
15Wrong answer0/320ms5172 KiB
16Accepted3/317ms4660 KiB
17Wrong answer0/324ms5180 KiB
18Accepted3/319ms4932 KiB
19Wrong answer0/321ms5164 KiB
20Accepted3/321ms5188 KiB