제출 #729370

#제출 시각아이디문제언어결과실행 시간메모리
729370PringCommuter Pass (JOI18_commuter_pass)C++14
31 / 100
290 ms24100 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; const int MXN = 100005; // int n, m, s, t, u, v, father[MXN], du[MXN], dv[MXN], uu = LLONG_MAX, vv = LLONG_MAX; int n, m, s, t, u, v, ds[MXN], du[MXN], dv[MXN], ans = LLONG_MAX, uu = LLONG_MAX, vv = LLONG_MAX; vector<pii> edge[MXN]; vector<int> path, father[MXN]; bitset<MXN> b; // void GET_PATH() { // b.reset(); // priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq; // pq.push({0, {0, s}}); // while (pq.size()) { // pair<int, pii> now = pq.top(); // pq.pop(); // if (b[now.second.second]) continue; // b[now.second.second] = true; // father[now.second.second] = now.second.first; // for (auto &i : edge[now.second.second]) { // if (b[i.first]) continue; // pq.push({now.first + i.second, {now.second.second, i.first}}); // } // } // int now = t; // path.push_back(now); // while (now != s) { // now = father[now]; // path.push_back(now); // } // } void DIJKSTRA(int start, int *arr) { b.reset(); priority_queue<pii, vector<pii>, greater<pii>> pq; pq.push({0, start}); while (pq.size()) { pii now = pq.top(); pq.pop(); if (b[now.second]) continue; b[now.second] = true; arr[now.second] = now.first; for (auto &i : edge[now.second]) { if (b[i.first]) continue; pq.push({now.first + i.second, i.first}); } } } void GET_PATH() { b.reset(); priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq; pq.push({0, {s, s}}); while (pq.size()) { pair<int, pii> now = pq.top(); pq.pop(); // if (b[now.second.second]) continue; if (b[now.second.second]) { if (ds[now.second.second] == now.first) father[now.second.second].push_back(now.second.first); continue; } b[now.second.second] = true; // father[now.second.second] = now.second.first; ds[now.second.second] = now.first; father[now.second.second].push_back(now.second.first); for (auto &i : edge[now.second.second]) { if (b[i.first]) continue; pq.push({now.first + i.second, {now.second.second, i.first}}); } } // int now = t; // path.push_back(now); // while (now != s) { // now = father[now]; // path.push_back(now); // } b.reset(); queue<int> q; q.push(t); while (q.size()) { int now = q.front(); q.pop(); if (b[now]) continue; b[now] = true; path.push_back(now); for (auto &i : father[now]) { if (b[i]) continue; q.push(i); } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int x, y, z; cin >> n >> m >> s >> t >> u >> v; for (int i = 0; i < m; i++) { cin >> x >> y >> z; edge[x].push_back({y, z}); edge[y].push_back({x, z}); } // GET_PATH(); GET_PATH(); if (s == u) { DIJKSTRA(v, dv); for (auto &i : path) { // cout << i << endl; ans = min(ans, dv[i]); } cout << ans << endl; } else { DIJKSTRA(u, du); DIJKSTRA(v, dv); for (auto &i : path) { uu = min(uu, du[i]); vv = min(vv, dv[i]); } cout << min(du[v], uu + vv) << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...