Submission #649644

#TimeUsernameProblemLanguageResultExecution timeMemory
649644RealSnakeCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
362 ms18252 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, s}); // subtask 1 and 2 bool b[n + 1] = {}; b[v] = 1; for(int i = 1; i <= n; i++) dist[i] = 1e18; dist[s] = 0; while(ss.size()) { auto [dis, x] = *ss.begin(); ss.erase(ss.begin()); if(dis > dist[x]) continue; if(x == t) 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; } } } 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...