Submission #1008967

#TimeUsernameProblemLanguageResultExecution timeMemory
1008967makanhuliaCommuter Pass (JOI18_commuter_pass)C++17
16 / 100
158 ms23752 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define pii pair<int, int> #define all(x) x.begin(), x.end() bool ckmin(int& a, int b){return b < a ? a = b, 1 : 0;} bool ckmax(int& a, int b){return b > a ? a = b, 1 : 0;} const int N = 2e5 + 5, mod = 1e9 + 7, INF = 1e18; vector<pii> a[N]; int dp[N], dp2[N], dp3[N], val[N]; signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; priority_queue<pii, vector<pii>, greater<pii>> pq; for(int i = 1; i <= m; i++) { int x, y, z; cin >> x >> y >> z; a[x].pb({y, z}); a[y].pb({x, z}); } for(int i = 1; i <= n; i++) dp[i] = dp3[i] = INF ; pq.push({0, s}); dp[s] = 0; while(!pq.empty()) { pii p = pq.top(); pq.pop(); if(p.fi > dp[p.se]) continue; for(auto i : a[p.se]) { if(dp[i.fi] > p.fi + i.se) { dp[i.fi] = p.fi + i.se; pq.push({dp[i.fi], i.fi}); } } } int mn = dp[t]; queue<int> q; q.push(t); val[t] = 1; while(!q.empty()) { int p = q.front(); q.pop(); for(auto i : a[p]) { if(dp[i.fi] + i.se == dp[p]) { if(!val[i.fi]) { val[i.fi] = 1; q.push(i.fi); } } } } pq.push({0, u}); dp2[u] = 0; while(!pq.empty()) { pii p = pq.top(); pq.pop(); if(p.fi > dp2[p.se]) continue; for(auto i : a[p.se]) { if(dp2[i.fi] > p.fi + i.se) { dp2[i.fi] = p.fi + i.se; pq.push({dp2[i.fi], i.fi}); } } } pq.push({0, v}); dp3[v] = 0; while(!pq.empty()) { pii p = pq.top(); pq.pop(); if(p.fi > dp3[p.se]) continue; for(auto i : a[p.se]) { if(dp3[i.fi] > p.fi + i.se) { dp3[i.fi] = p.fi + i.se; pq.push({dp3[i.fi], i.fi}); } } } int ans = INF; for(int i = 1; i <= n; i++) { if(val[i]) { ans = min(ans, dp3[i]); } } cout << ans << endl ; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:36:9: warning: unused variable 'mn' [-Wunused-variable]
   36 |     int mn = dp[t];
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...