Submission #237804

#TimeUsernameProblemLanguageResultExecution timeMemory
237804aggu_01000101Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
599 ms25732 KiB
#include <bits/stdc++.h> #define int long long #define INF 10000000000000000 #define lchild(i) (i*2 + 1) #define rchild(i) (i*2 + 2) #define mid(l, u) ((l+u)/2) #define MOD 1000000007 using namespace std; int n, m, s, t, u, v, sp; vector<pair<int, int>> adj[100005]; vector<int> opte[100005]; bool visited[100005]; int dij(int start, int arr[]){ bool vis[n+1]; for(int i = 1;i<=n;i++) vis[i] = false; for(int i = 1;i<=n;i++) arr[i] = INF; arr[start] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, start}); while(!pq.empty()){ pair<int, int> curr = pq.top(); pq.pop(); if(vis[curr.second]) continue; vis[curr.second] = true; if(curr.first > arr[curr.second]) continue; for(pair<int, int> j: adj[curr.second]){ if((j.second + curr.first)>arr[j.first]) continue; arr[j.first] = j.second + curr.first; pq.push({arr[j.first], j.first}); } } } void dfs(int x, int dp[]){ if(visited[x]) return; visited[x] = true; for(int j: opte[x]){ if(!visited[j]) dfs(j, dp); dp[x] = min(dp[x], dp[j]); } } int findans(int a1[], int a2[]){ int dp[n+1]; for(int i = 1;i<=n;i++) dp[i] = a2[i]; for(int i = 1;i<=n;i++){ dfs(i, dp); } int ans = INF; for(int i = 1;i<=n;i++){ ans = min(ans, dp[i] + a1[i]); } return ans; } signed main(){ cin>>n>>m>>s>>t>>u>>v; for(int i = 0;i<m;i++){ int a, b, c; cin>>a>>b>>c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } int sd[n+1], td[n+1], ud[n+1], vd[n+1]; dij(s, sd); dij(t, td); dij(u, ud); dij(v, vd); sp = sd[t]; int ans = ud[v]; for(int i = 1;i<=n;i++){ visited[i] = false; for(pair<int, int> j: adj[i]){ if (sd[i] + j.second + td[j.first] == sp){ opte[i].push_back(j.first); opte[j.first].push_back(i); } } } ans = min(ans, findans(ud, vd)); ans = min(ans, findans(vd, ud)); cout<<ans<<endl; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'long long int dij(long long int, long long int*)':
commuter_pass.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...