제출 #227806

#제출 시각아이디문제언어결과실행 시간메모리
227806jiahngCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
2084 ms31900 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector <ll> vi; typedef vector <pi> vpi; #define f first #define s second #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0) #define maxn 200001 #define INF 1e10 #define int ll typedef pair <pi,int> pii; int N,M,S,T,U,V; map <int,int[maxn] > dist; vpi adj[maxn]; vi dag[maxn]; int dp[maxn]; int minE[maxn]; int minS[maxn]; int dpf(int x){ if (dp[x] != -1) return dp[x]; dp[x] = INF; int E = INF; int mnS = INF; aFOR(i,dag[x]){ E = min(E,minE[x]); mnS = min(mnS,minS[x]); dp[x] = min(dp[x],dpf(i)); } dp[x] = min(dp[x],dist[U][x] + E); dp[x] = min(dp[x],dist[V][x] + mnS); dp[x] = min(dp[x],dist[U][x] + dist[V][x]); return dp[x]; } int dfs(int x){ //to find minE minE[x] = dist[V][x]; minS[x] = dist[U][x]; aFOR(i,dag[x]){ dfs(i); minE[x] = min(minE[x],minE[i]); minS[x] = min(minS[x],minS[i]); } return minE[x]; } int32_t main(){ fast; cin>>N>>M>>S>>T>>U>>V; vector <pii> edges; FOR(i,0,M-1){ int a,b,c; cin>>a>>b>>c; adj[a].pb(pi(b,c)); adj[b].pb(pi(a,c)); edges.pb(pii(pi(a,b),c)); } int dijarr[4] = {S,T,U,V}; FOR(i,0,3){ int rt = dijarr[i]; priority_queue <pi> pq; mem(dist[rt],-1); dist[rt][rt] = 0; pq.push(pi(0,rt)); while (!pq.empty()){ pi cur = pq.top(); pq.pop(); if (dist[rt][cur.s] != cur.f) continue; aFOR(i,adj[cur.s]){ if (dist[rt][i.f] == -1 || dist[rt][i.f] > cur.f + i.s){ dist[rt][i.f] = cur.f + i.s; pq.push(pi(dist[rt][i.f],i.f)); } } } } aFOR(i,edges){ int a = i.f.f, b = i.f.s, c = i.s; if (dist[S][a] + c + dist[T][b] == dist[S][T]){ dag[a].pb(b); //cout<<a<<' '<<b<<'\n'; }else if(dist[S][b] + c + dist[T][a] == dist[S][T]){ dag[b].pb(a); //cout<<b<<' '<<a<<'\n'; } } dfs(S); mem(dp,-1); int ans = min(dist[U][V],dpf(S)); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...