Submission #1167673

#TimeUsernameProblemLanguageResultExecution timeMemory
1167673KnightCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
3 ms5704 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") using namespace std; long long ds[100001], dt[100001], du[100001], dv[100001], l, a; int main() { ifstream cin("in.in"); ios_base::sync_with_stdio(0);cin.tie(0); int n, m, s, u, t, v, x, y; vector<pair<int, long long>> g[100001]; priority_queue<pair<long long, int>> q; fill(ds, ds+100001, LLONG_MAX); fill(du, du+100001, LLONG_MAX); fill(dt, dt+100001, LLONG_MAX); fill(dv, dv+100001, LLONG_MAX); cin >> n >> m; cin >> s >> t >> u >> v; for(int i=1;i<=m;i++){ cin >> x >> y >> l; g[x].push_back({y, l}); g[y].push_back({x, l}); } ds[s] = 0; q.push({0, s}); while(!q.empty()){ x = q.top().second; l = q.top().first; q.pop(); for(pair<int, long long> i : g[x]){ if(ds[i.first]>(l+i.second)){ ds[i.first] = l+i.second; q.push({ds[i.first], i.first}); } } } dt[t] = 0; q.push({0, t}); while(!q.empty()){ x = q.top().second; l = q.top().first; q.pop(); for(pair<int, long long> i : g[x]){ if(dt[i.first]>(l+i.second)){ dt[i.first] = l+i.second; q.push({dt[i.first], i.first}); } } } du[u] = 0; q.push({0, u}); while(!q.empty()){ x = q.top().second; l = q.top().first; q.pop(); for(pair<int, long long> i : g[x]){ if(du[i.first]>(l+i.second)){ du[i.first] = l+i.second; q.push({du[i.first], i.first}); } } } dv[v] = 0; q.push({0, v}); while(!q.empty()){ x = q.top().second; l = q.top().first; q.pop(); for(pair<int, long long> i : g[x]){ if(dv[i.first]>(l+i.second)){ dv[i.first] = l+i.second; q.push({dv[i.first], i.first}); } } } a = du[v]; for(int i=1;i<=n;i++){ l = ds[t]; if(l==ds[i]+dt[i]){ a = min(a, dv[i]); } } cout << a << '\n'; 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...