254422026-02-20 09:53:36KevinKaktusz túra (45 pont)cpp17Wrong answer 32/4523ms4704 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(n);
    check.resize(n, 0);
    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
base32/45
1Accepted0/01ms316 KiB
2Wrong answer0/019ms4660 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/21ms316 KiB
11Wrong answer0/21ms508 KiB
12Accepted3/318ms4184 KiB
13Accepted3/323ms4512 KiB
14Accepted3/319ms4148 KiB
15Wrong answer0/321ms4700 KiB
16Accepted3/317ms4444 KiB
17Wrong answer0/323ms4704 KiB
18Accepted3/317ms4552 KiB
19Wrong answer0/320ms4544 KiB
20Accepted3/320ms4600 KiB