Submission #1009049

#TimeUsernameProblemLanguageResultExecution timeMemory
1009049makanhuliaCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
479 ms83140 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() #define ar array<int, 3> 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<ar> a[N]; vector<int> e[N]; int dp[N], dp2[N], dp3[N], val[N], vis[N], dp4[N]; map<pii, int> mp, mp2; 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, i}); a[y].pb({x, z, i}); } for(int i = 1; i <= n; i++) dp[i] = dp3[i] = dp2[i] = dp4[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[0]] > p.fi + i[1]) { dp[i[0]] = p.fi + i[1]; pq.push({dp[i[0]], i[0]}); } } } int mn = dp[t]; queue<int> q; q.push(t); while(!q.empty()) { int p = q.front(); q.pop(); for(auto i : a[p]) { // cout << dp[i[0]] << " " << dp[p] << " " << i[0] << " " << i[1] << " " << i[2] << " " << p << endl; if(dp[i[0]] + i[1] == dp[p]) { if(!val[i[2]]) { mp[{i[0], p}] = 1; mp2[{p, i[0]}] = 1; val[i[2]] = 1; q.push(i[0]); } } } } pq.push({0, u}); dp2[u] = 0; // for(int i = 1; i <= m; i++) cout << val[i] << " "; // cout << endl; 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[0]] > p.fi + (mp[{p.se, i[0]}] ? 0 : i[1])) { dp2[i[0]] = p.fi + (mp[{p.se, i[0]}] ? 0 : i[1]); pq.push({dp2[i[0]], i[0]}); } } } pq.push({0, u}); while(!pq.empty()) { pii p = pq.top(); pq.pop(); if(p.fi > dp4[p.se]) continue; for(auto i : a[p.se]) { if(dp4[i[0]] > p.fi + (mp2[{p.se, i[0]}] ? 0 : i[1])) { dp4[i[0]] = p.fi + (mp2[{p.se, i[0]}] ? 0 : i[1]); pq.push({dp4[i[0]], i[0]}); } } } // for(int i = 1; i <= n; i++) cout << dp2[i] << " "; // cout << endl; 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[0]] > p.fi + i[1]) { dp3[i[0]] = p.fi + i[1]; pq.push({dp3[i[0]], i[0]}); } } } int ans = INF; for(int i = 1; i <= n; i++) { if(val[i]) { ans = min(ans, dp3[i] + min(dp2[i], dp4[i])); } } cout << ans << endl ; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:39:9: warning: unused variable 'mn' [-Wunused-variable]
   39 |     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...