Submission #494784

#TimeUsernameProblemLanguageResultExecution timeMemory
494784kamalsharmaa9Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
398 ms23988 KiB
//https://pastebin.com/jVURaNCJ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define N 100005 #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define piii pair<pair<int,int>,pair<int,int>> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int du[N]; int dv[N]; int ans = inf; vector<pii>gr[N]; void dijkstra1(int node, int n, int dist[]) { for (int i = 0; i <= n; i++) dist[i] = inf; dist[node] = 0; priority_queue<pii, vector<pii>, greater<pii>>q; q.push({dist[node], node}); int val; while (!q.empty()) { node = q.top().ss; val = q.top().ff; q.pop(); if (dist[node] < val) continue; for (auto child : gr[node]) { if (dist[child.ff] > dist[node] + child.ss) { dist[child.ff] = dist[node] + child.ss; q.push({dist[child.ff], child.ff}); } } } } int dist[N]; int dist2[2][N]; void dijkstra2(int node, int n, int end) { for (int i = 0; i <= n; i++) { dist[i] = dist2[0][i] = dist2[1][i] = inf; } dist[node] = 0; priority_queue<pii, vector<pii>, greater<pii>>q; q.push({0, node}); dist2[0][node] = du[node]; dist2[1][node] = dv[node]; while (!q.empty()) { node = q.top().ss; int val = q.top().ff; q.pop(); for (auto child : gr[node]) { int to_com = min( dist2[0][node], du[child.ff]) + min(dist2[1][node], dv[child.ff]); if (dist[child.ff] > dist[node] + child.ss) { // cout << child.ff << endl; dist[child.ff] = dist[node] + child.ss; dist2[0][child.ff] = min(dist2[0][node], du[child.ff]); dist2[1][child.ff] = min(dist2[1][node], dv[child.ff]); q.push({dist[child.ff], child.ff}); } else if (dist[child.ff] == dist[node] + child.ss && dist2[0][child.ff] + dist2[1][child.ff] > to_com) { dist2[0][child.ff] = min( dist2[0][node], du[child.ff]); dist2[1][child.ff] = min(dist2[1][node], dv[child.ff]); } } } ans = min(ans, dist2[0][end] + dist2[1][end]); //cout << dist2[0][7] << " " << dist2[1][7] << " " << dist2[0][2] << " " << dist2[1][2] << endl; } int32_t main() { c_p_c(); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; gr[a].pb({b, c}); gr[b].pb({a, c}); } dijkstra1(u, n, du); dijkstra1(v, n, dv); ans = dv[u]; dijkstra2(s, n, t); dijkstra2(t, n, s); cout << ans << '\n'; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void dijkstra2(long long int, long long int, long long int)':
commuter_pass.cpp:86:9: warning: unused variable 'val' [-Wunused-variable]
   86 |     int val = q.top().ff;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...