Submission #838003

#TimeUsernameProblemLanguageResultExecution timeMemory
838003NoLoveCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
358 ms262144 KiB
/**
 *    author : Lăng Trọng Đạt
 *    created: 2023-08-26
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;

const int MAXN = 1e5 + 5;
const int INF = 1e18;
vector<pii> adj[MAXN];
int far[MAXN];
int n, m, x, y, s, t;
int a, b, w;
int res = INF;
set<pii> bought;

void truy_vet() {
    int endd = t, start = far[t]; // both endpoint of railway
    bought.clear();
    while (start) {
        bought.insert({start, endd});
        bought.insert({endd, start});
        endd = start;
        start = far[start];
    }
}

int dijkstra(int start, int target, bool truy) {
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    vector<int> d(n + 1, INF); // minimum distance from start to node i
    pq.push({0, start});
    d[start] = 0;
    while (pq.size()) {
        auto[dist, v] = pq.top(); pq.pop();
//        db(dist, v, d[v])
        if (dist != d[v]) continue;
        if (v == target) {
//            db(res, dist, target, pq.size())
            if (!truy) return dist;
            truy_vet();
            res = min(res, dijkstra(x, y, 0));
            continue;
        }
        for (auto[u, w] : adj[v]) {
//            db(u, v, w, dist, truy)
            if (!truy && bought.count({u, v})) w = 0;
            if (d[u] > w + dist or (truy && d[u] == w + dist)) {
                d[u] = w + dist;
                pq.push({d[u], u});
                if (truy) far[u] = v;
            }
        }
    }
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    }

    cin >> n >> m >> s >> t >> x >> y;
    while (m--) {
        cin >> a >> b >> w;
        adj[a].pb({b, w});
        adj[b].pb({a, w});
    }

    dijkstra(s, t, true);
    cout << res;
}

Compilation message (stderr)

commuter_pass.cpp: In function 'int64_t dijkstra(int64_t, int64_t, bool)':
commuter_pass.cpp:44:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |         auto[dist, v] = pq.top(); pq.pop();
      |             ^
commuter_pass.cpp:54:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |         for (auto[u, w] : adj[v]) {
      |                  ^
commuter_pass.cpp:39:52: warning: control reaches end of non-void function [-Wreturn-type]
   39 |     priority_queue<pii, vector<pii>, greater<pii>> pq;
      |                                                    ^~
commuter_pass.cpp: In function 'int32_t main()':
commuter_pass.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...