Submission #649673

#TimeUsernameProblemLanguageResultExecution timeMemory
649673RealSnakeCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
2100 ms33968 KiB
#include "bits/stdc++.h" #define ll long long using namespace std; int n, m, s, t, u, v; int a[100005]; ll dist[100005], dist2[100005]; vector<pair<int, ll>> node[100005], node2[100005]; int ind; ll ans = 1e18; void solve() { for(int i = 0; i < ind - 1; i++) { int b1 = a[i], b2 = a[i + 1]; int sz = node[b1].size(); for(int j = 0; j < sz; j++) { if(node2[b1][j].first == b2) { node2[b1][j].second = 0; break; } } sz = node[b2].size(); for(int j = 0; j < sz; j++) { if(node2[b2][j].first == b1) { node2[b2][j].second = 0; break; } } } set<pair<ll, int>> ss; ss.insert({0, u}); for(int i = 1; i <= n; i++) dist2[i] = 1e18; dist2[u] = 0; while(ss.size()) { auto [dis, x] = *ss.begin(); ss.erase(ss.begin()); if(dis > dist2[x]) continue; if(x == v) { ans = min(ans, dis); break; } for(auto [y, d] : node2[x]) { if(dis + d < dist2[y]) { dist2[y] = dis + d; ss.insert({dist2[y], y}); } } } for(int i = 0; i < ind - 1; i++) { int b1 = a[i], b2 = a[i + 1]; int sz = node[b1].size(); for(int j = 0; j < sz; j++) { if(node2[b1][j].first == b2) { node2[b1][j].second = node[b1][j].second; break; } } sz = node[b2].size(); for(int j = 0; j < sz; j++) { if(node2[b2][j].first == b1) { node2[b2][j].second = node[b2][j].second; break; } } } } void dfs(int x) { a[ind++] = x; if(x == t) { solve(); return; } for(auto [y, d] : node[x]) { if(dist[x] + d <= dist[y]) { dist[y] = dist[x] + d; dfs(y); } } ind--; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 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}); node2[a].push_back({b, c}); node2[b].push_back({a, c}); } for(int i = 1; i <= n; i++) dist[i] = 1e18; dist[s] = 0; dfs(s); cout << ans; 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...