제출 #1187543

#제출 시각아이디문제언어결과실행 시간메모리
1187543sergiomoncadamcCommuter Pass (JOI18_commuter_pass)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
using ld = long double;
#define pb push_back
#define sz size()
#define int long long
typedef pair<int, ll> pil;

const int maxn = 1e5 + 1;
const ll inf = 1e15;
vector<set<pil>> graph(maxn);

struct comp{
    bool operator() (pil a, pil b){
        return a.second > b.second;
    }
};

struct edge {
    int u, v; ll w;

    // Ordenar las aristas por el menor peso
    bool operator<(const edge& that) const {
        return w < that.w; // Cambiar '<' por '>' para hallar el Maximal Spanning Tree
    }
};

// Complejidad O(m*log(n))
void dijkstra(int source, int n, vector<ll>& d){
    for(int i = 1; i <= n; i++) d[i] = inf;
    d[source] = 0;
    priority_queue<pil, vector<pil>, comp> pq;
    pq.push({source, 0});
    while(!pq.empty()){
        int u = pq.top().first; ll w1 = pq.top().second;
        pq.pop();
        if(d[u] < w1) continue;
        for(pil edge : graph[u]){
            int v = edge.first; ll w2 = edge.second;
            if(d[v] > w1 + w2){
                d[v] = w1 + w2;
                pq.push({v, d[v]});
            }
        }
    }
}

void change(int s, int t, vector<ll>& ds, vector<ll>& dt, vector<edge>& edges){
    for(edge e : edges){
        int u = e.u, v = e.v; ll w = e.w;
        if(ds[u] + w + dt[v] == ds[t]){
            graph[u].erase({v, w});
            graph[u].insert({v, 0});
        }

        else if(ds[v] + w + dt[u] == ds[t]){
            graph[v].erase({u, w});
            graph[v].insert({u, 0});
        }
    }
}

signed solver(){
    int n, m, s, t, u, v; cin>>n>>m>>s>>t>>u>>v;
    vector<edge> edges;
    for(int i = 0; i < m; i++){
        int a, b; ll w;
        cin>>a>>b>>w;
        edges.pb({a, b, w});
        graph[a].insert({b, w});
        graph[b].insert({a, w});
    }
    vector<ll> ds(n+1), dt(n+1), du(n+1), dv(n+1);
    dijkstra(s, n, ds);
    dijkstra(t, n, dt);
    change(s, t, ds, dt, edges);
    dijkstra(u, n, du);
    dijkstra(v, n, dv);

    cout<<min(du[v], dv[u])<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--){
        solver();
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'int solver()':
commuter_pass.cpp:83:1: warning: no return statement in function returning non-void [-Wreturn-type]
   83 | }
      | ^
At global scope:
cc1plus: error: '::main' must return 'int'