제출 #892451

#제출 시각아이디문제언어결과실행 시간메모리
892451oblantisCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
183 ms18812 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e14 + 10000;
const int mod = 1e9+7;
const int maxn = 1e5 + 12;
vt<pii> g[maxn];
void ope(vll &a, int st){
	a[st] = 0;
	priority_queue<pair<ll, int>, vt<pair<ll, int>>, greater<pair<ll, int>>> pq;
	pq.push({0, st});
	while(!pq.empty()){
		pair<ll, int> nw = pq.top();
		pq.pop();
		if(a[nw.ss] != nw.ff)continue;
		for(auto i : g[nw.ss]){
			if(nw.ff + i.ss < a[i.ff]) {
				a[i.ff] = nw.ff + i.ss;
				pq.push({a[i.ff], i.ff});
			}
		}
	}
}
void solve() {
	int n, m, s, t, u, v;
	cin >> n >> m >> s >> t >> u >> v;
	for(int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		g[a].pb({b, c});
		g[b].pb({a, c});
	}
	s--, t--, u--, v--;
	vll a(n, inf), c(n, inf), d(n, inf);
	ope(a, s), ope(c, u), ope(d, v);
	ll ans = c[v];
	vt<bool> was(n);
	vll D(n, inf), C(n, inf);
	priority_queue<pair<ll, int>> pq;
	pq.push({a[t], t});
	was[t] = 1;
	while(!pq.empty()){
		pair<ll, int> nw = pq.top();
		C[nw.ss] = min(C[nw.ss], c[nw.ss]), D[nw.ss] = min(D[nw.ss], d[nw.ss]);
		ans = min(ans, min(C[nw.ss] + d[nw.ss], D[nw.ss] + c[nw.ss]));
		pq.pop();
		for(auto i : g[nw.ss]){
			if(a[i.ff] + i.ss == nw.ff){
				C[i.ff] = min(C[i.ff], C[nw.ss]);
				D[i.ff] = min(D[i.ff], D[nw.ss]);
				if(!was[i.ff]){
					was[i.ff] = 1;
					pq.push({a[i.ff], i.ff});
				}
			}
		}
	}
	cout << ans;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int times = 1;
	//cin >> times;
	for(int i = 1; i <= times; i++) {
		solve();
	}
	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...