제출 #649648

#제출 시각아이디문제언어결과실행 시간메모리
649648RealSnakeCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
277 ms18668 KiB
#include "bits/stdc++.h" #define ll long long using namespace std; int par[100005]; ll dist[100005]; vector<pair<int, ll>> node[100005]; signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; for(int i = 0; i < m; i++) { int a, b; ll c; cin >> a >> b >> c; node[a].push_back({b, c}); node[b].push_back({a, c}); } set<pair<ll, int>> ss; ss.insert({0, t}); // subtask 1 and 2 bool b[n + 1] = {}; b[v] = 1; for(int i = 1; i <= n; i++) dist[i] = 1e18; dist[t] = 0; while(ss.size()) { auto [dis, x] = *ss.begin(); ss.erase(ss.begin()); if(dis > dist[x]) continue; if(x == s) break; for(auto [y, d] : node[x]) { if(dis + d < dist[y]) { if(y != v) b[y] = b[x]; par[y] = x; dist[y] = dis + d; ss.insert({dist[y], y}); } else if(dis + d == dist[y] && b[x]) { b[y] = b[x]; par[y] = x; } } } swap(s, t); while(t != s) { int sz = node[t].size(); for(int i = 0; i < sz; i++) { if(node[t][i].first == par[t]) { node[t][i].second = 0; break; } } sz = node[par[t]].size(); for(int i = 0; i < sz; i++) { if(node[par[t]][i].first == t) { node[par[t]][i].second = 0; break; } } t = par[t]; } ss.clear(); ss.insert({0, u}); for(int i = 1; i <= n; i++) dist[i] = 1e18; dist[u] = 0; while(ss.size()) { auto [dis, x] = *ss.begin(); ss.erase(ss.begin()); if(dis > dist[x]) continue; if(x == v) { cout << dis; return 0; } for(auto [y, d] : node[x]) { if(dis + d < dist[y]) { dist[y] = dis + d; ss.insert({dist[y], y}); } } } 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...