제출 #1086847

#제출 시각아이디문제언어결과실행 시간메모리
1086847peacebringer1667Commuter Pass (JOI18_commuter_pass)C++17
16 / 100
257 ms24084 KiB
#include<bits/stdc++.h> #define ll long long #define ldb long double #define fi first #define se second #define sza(a) (int)a.size() #define pir pair<int,int> #define pirll pair<ll,int> #define int long long using namespace std; const int maxn = 1e5 + 5; ll dist[maxn][3],D = 0,dp[maxn]; bool mark[maxn]; vector <vector<pir>> vec(maxn); void input(int n,int m){ while (m--){ int u,v,w; cin >> u >> v >> w; vec[u].push_back({v,w}); vec[v].push_back({u,w}); } } void dijkstra(int source,int n,int st){ for (int i = 1 ; i <= n ; i++) mark[i] = 0; priority_queue <pirll,vector<pirll>,greater<pirll>> pq; pq.push({0,source}); while (pq.size()){ pirll t = pq.top(); pq.pop(); int u = t.se;ll w = t.fi; if (mark[u]) continue; mark[u] = 1; dist[u][st] = w; for (pir v : vec[u]) if (!mark[v.fi]) pq.push({v.se + w,v.fi}); } D = dist[source][0]; } void solve(int source,int n){ for (int i = 1 ; i <= n ; i++) mark[i] = 0; priority_queue <pirll,vector<pirll>,greater<pirll>> pq; pq.push({0,source}); while (pq.size()){ pirll t = pq.top(); pq.pop(); int u = t.se;ll w = t.fi; if (mark[u]) continue; mark[u] = 1; dp[u] = w; for (pir node : vec[u]) if (!mark[node.fi]){ int v = node.fi,e = node.se; if (dist[u][0] + e + dist[v][1] == D) pq.push({w,v}); else pq.push({w + e,v}); } } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n,m,S,T,U,V; cin >> n >> m >> S >> T >> U >> V; input(n,m); dijkstra(S,n,0); dijkstra(T,n,1); solve(U,n); cout << dp[V]; 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...