Submission #70763

#TimeUsernameProblemLanguageResultExecution timeMemory
70763someone_aaCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
651 ms14044 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 100100; ll dist[maxn][4], n, m, s, t, u, v; ll dp[maxn][2]; bool visited[maxn]; vector<pair<int,int> > g[maxn]; /* dist[i][0] - dist to i from u dist[i][1] - dist to i from v dist[i][2] - dist to i from s dist[i][3] - dist to i from t */ void dijkstra(int start, int x) { memset(visited,false,sizeof(visited)); for(int i=0;i<=n;i++) { dist[i][x] = 10000000LL * INT_MAX; } dist[start][x] = 0LL; //visited[start] = true; priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > pq; pq.push(mp(0, start)); while(!pq.empty()) { int curr = pq.top().second; pq.pop(); if(visited[curr]) continue; visited[curr] = true; for(auto i:g[curr]) { if(dist[curr][x] + i.second < dist[i.first][x] && !visited[i.first]) { dist[i.first][x] = dist[curr][x] + i.second; pq.push(mp(dist[i.first][x], i.first)); } } } } void get_dp(int start, int x) { memset(visited,false,sizeof(visited)); for(int i=0;i<=n;i++) { dp[i][x] = dist[i][1]; } queue<int>q; q.push(start); while(!q.empty()) { int curr = q.front(); q.pop(); for(auto i:g[curr]) { if(x == 0) { if(dist[curr][2] + i.second + dist[i.first][3] == dist[t][2]) { dp[i.first][0] = min(dp[i.first][0], dp[curr][0]); } } else { if(dist[curr][3] + i.second + dist[i.first][2] == dist[s][3]) { dp[i.first][1] = min(dp[i.first][1], dp[curr][1]); } } if(!visited[i.first]) { visited[i.first] = true; q.push(i.first); } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>m; cin>>s>>t; cin>>u>>v; int x, y, z; for(int i=0;i<m;i++) { cin>>x>>y>>z; g[x].pb(mp(y,z)); g[y].pb(mp(x,z)); } dijkstra(u, 0); dijkstra(v, 1); dijkstra(s, 2); dijkstra(t, 3); get_dp(s, 0); get_dp(t, 1); ll result = LLONG_MAX; for(int i=1;i<=n;i++) { for(auto j:g[i]) { if(dist[i][2] + dist[j.first][3] + j.second == dist[t][2]) { result = min(result, dist[i][0] + min(dp[i][0], dp[i][1])); } } } cout<<min(result, dist[v][0]); 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...