Submission #551541

#TimeUsernameProblemLanguageResultExecution timeMemory
551541CyberSleeperCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
365 ms26048 KiB
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl #define all(x) x.begin(), x.end() #define fi first #define se second #define mp make_pair #define pb push_back #define ll long long #define ull unsigned long long #define pll pair<ll, ll> #define pii pair<int, int> #define ld long double #define nl endl #define tb '\t' #define sp ' ' #define sqr(x) (x)*(x) #define arr3 array<int, 3> using namespace std; const int MX=100005, MOD=1000000007, BLOCK=160, INF=2e9+7, LG=62; const ll INFF=1000000000000000007; const ld ERR=1e-6, pi=3.14159265358979323846; int N, M, S, T, U, V, st[4]; ll dist[4][MX], ans=INFF, vis[2][MX]; vector<pll> adj[MX]; bool valid(int x, int y, ll v=0){ return (dist[0][x]+v+dist[1][y]==dist[0][T]); } ll DP(int x, int dir){ ll &ret=vis[dir][x]; if(ret==-1){ ret=dist[3][x]; for(pll i:adj[x]){ if(dir){ if(valid(x, i.fi, i.se)) ret=min(ret, DP(i.fi, dir)); }else{ if(valid(i.fi, x, i.se)) ret=min(ret, DP(i.fi, dir)); } } } return ret; } int main(){ fastio; memset(vis, -1, sizeof(vis)); cin >> N >> M >> S >> T >> U >> V; st[0]=S; st[1]=T; st[2]=U; st[3]=V; for(int i=0, u, v, w; i<M; i++){ cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } for(int ii=0; ii<4; ii++){ priority_queue<pll, vector<pll>, greater<pll>> PQ; PQ.push({0, st[ii]}); for(int i=0; i<=N; i++) dist[ii][i]=INFF; dist[ii][st[ii]]=0; while(PQ.size()){ ll idx=PQ.top().se, cost=PQ.top().fi; PQ.pop(); if(cost>dist[ii][idx]) continue; for(pll i:adj[idx]){ if(cost+i.se<dist[ii][i.fi]){ dist[ii][i.fi]=cost+i.se; PQ.push({dist[ii][i.fi], i.fi}); } } } } ans=dist[2][V]; vis[0][V]=vis[1][V]=0; for(int i=1; i<=N; i++){ if(valid(i, i)){ ans=min(ans, dist[2][i]+min(DP(i, 1), DP(i, 0))); } } cout << ans << nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...