제출 #1036869

#제출 시각아이디문제언어결과실행 시간메모리
1036869vaneaCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
194 ms26728 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mxN = 1e5+10;

vector<array<ll, 2>> adj[mxN];
ll du[mxN], dv[mxN], ds[mxN], dp[mxN][2], ans;
bool vis[mxN];

void dijkstra(int start, ll arr[]) {
    memset(vis, false, sizeof vis);
    priority_queue<array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> q;
    q.push({0, start});
    arr[start] = 0;
    while(!q.empty()) {
        auto dist = q.top()[0], node = q.top()[1];
        q.pop();
        if(!vis[node]) {
            vis[node] = true;
            arr[node] = dist;
            for(auto [it, w] : adj[node]) {
                if(!vis[it]) {
                    q.push({dist+w, it});
                }
            }
        }
    }
}

void dijkstra2(int start, int fin) {
    memset(ds, 0x3F, sizeof ds);
    memset(dp, 0x3F, sizeof dp);
    memset(vis, false, sizeof vis);
    priority_queue<array<ll, 3>, vector<array<ll, 3>>, greater<array<ll, 3>>> q;
    q.push({0, start, 0});
    while(!q.empty()) {
        auto dist = q.top()[0], node = q.top()[1], p = q.top()[2];
        q.pop();
        if(!vis[node]) {
            dp[node][0] = min(dp[p][0], du[node]);
            dp[node][1] = min(dp[p][1], dv[node]);
            vis[node] = true;
            ds[node] = dist;
            for(auto [it, w] : adj[node]) {
                if(!vis[it]) {
                    q.push({dist+w, it, node});
                }
            }
        }
        else {
            if(dist == ds[node]) {
                ll f = min(dp[p][0], du[node]);
                ll s = min(dp[p][1], dv[node]);
                if(f+s < dp[node][0]+dp[node][1]) {
                    dp[node][0] = f;
                    dp[node][1] = s;
                }
            }
        }
    }
    ans = min(ans, dp[fin][0]+dp[fin][1]);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, s, t, u, v;
    cin >> n >> m >> s >> t >> u >> v;
    while(m--) {
        ll a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    dijkstra(u, du);
    dijkstra(v, dv);

    ans = du[v];

    dijkstra2(s, t);
    cout << ans;
    return 0;
}

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

commuter_pass.cpp: In function 'void dijkstra(int, ll*)':
commuter_pass.cpp:22:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |             for(auto [it, w] : adj[node]) {
      |                      ^
commuter_pass.cpp: In function 'void dijkstra2(int, int)':
commuter_pass.cpp:45:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |             for(auto [it, w] : adj[node]) {
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...