제출 #679340

#제출 시각아이디문제언어결과실행 시간메모리
679340Hiennoob123Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
2096 ms31552 KiB
#include<bits/stdc++.h> #define ll long long #define int long long #define ld long double #define cd complex<ld> #define pll pair<ll,ll> #define pii pair<int,int> #define pld pair<ld,ld> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; ll n, m; vector<pll> T[100005]; ll save[4]; ll dis[4][10005]; bool chk[100005]; bool in[100005]; ll dp[100005]; ll sum[100005]; vector<ll> adj[100005]; ll ans = LLONG_MAX; void dijsktra(ll type) { for(int i = 1; i<= n; i++) dis[type][i] = LLONG_MAX; for(int i = 1; i<= n; i++) chk[i] = 0; priority_queue<pll,vector<pll>, greater<pll>> q; dis[type][save[type]] = 0; q.push(mp(0 , save[type])); while(!q.empty()) { ll path = q.top().fi, x = q.top().se; q.pop(); if(chk[x]||dis[type][x]!=path) continue; //cout << type << " " << path << " " << x << "-\n"; chk[x] = 1; for(auto u: T[x]) { ll cur = path+u.se; if(cur<dis[type][u.fi]) { dis[type][u.fi] = cur; q.push(mp(dis[type][u.fi], u.fi)); } } } } void dfs(ll v) { for(auto x: adj[v]) { dfs(x); dp[v] = min(dp[v], dp[x]); } ans = min(ans, dp[v]+sum[v]); } void solve() { cin >> n >> m; cin >> save[2] >> save[3] >> save[0] >> save[1]; for(int i = 0 ;i< m; i++) { ll a, b, c; cin >> a >> b >> c; T[a].push_back(mp(b,c)); T[b].push_back(mp(a,c)); } dijsktra(2); dijsktra(3); //cout << dis[2][save[3]] << "\n"; for(int i = 1; i<= n; i++) { //cout << dis[2][i] << " " << dis[3][i] << " " << i << "\n"; if(dis[2][save[3]]==dis[2][i]+dis[3][i]) { //cout << i << "\n"; in[i] = 1; } } for(int i = 1; i<= n; i++) { if(!in[i]) continue; //cout << i << "\n"; for(auto x: T[i]) { if(!in[x.fi]||dis[2][i]+x.se!=dis[2][x.fi]) continue; adj[i].push_back(x.fi); //cout << i << " " << x.fi << "\n"; } } dijsktra(0); dijsktra(1); for(int i = 1; i<= n; i++) { //cout << dis[1][i] << " " << dis[0][i] << " " << i << "\n"; dp[i] = dis[1][i]; sum[i] = dis[0][i]; } dfs(save[2]); for(int i = 1 ; i<= n; i++) { //cout << dp[i] << " " << sum[i] << " " << i << "\n"; } swap(save[0],save[1]); dijsktra(0); dijsktra(1); for(int i = 1; i<= n; i++) { dp[i] = dis[1][i]; sum[i] = dis[0][i]; } dfs(save[2]); cout << min(ans, dis[0][save[1]]); } signed main() { //freopen("IN.txt","r",stdin); //freopen("OUT.txt","w",stdout); ios_base::sync_with_stdio(NULL) ; cin.tie(nullptr) ; cout.tie(nullptr); ll t = 1; //cin >> t; while(t--) { solve(); cout << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...