254452026-02-20 09:58:45KevinKaktusz túra (45 pont)cpp17Hibás válasz 37/4530ms4760 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, LONG_LONG_MIN);
    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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base37/45
1Elfogadva0/01ms316 KiB
2Hibás válasz0/028ms4656 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms316 KiB
10Elfogadva2/21ms316 KiB
11Hibás válasz0/21ms316 KiB
12Elfogadva3/321ms4160 KiB
13Elfogadva3/324ms4112 KiB
14Elfogadva3/319ms4368 KiB
15Elfogadva3/326ms4660 KiB
16Elfogadva3/320ms4320 KiB
17Hibás válasz0/330ms4760 KiB
18Elfogadva3/319ms4700 KiB
19Hibás válasz0/326ms4572 KiB
20Elfogadva3/325ms4744 KiB