이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct point{
	int64_t u,pp,bb;
};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int64_t n,m;cin>>n>>m;
	int64_t S,T;cin>>S>>T;
	--S;--T;
	int64_t U,V;cin>>U>>V;
	--U;--V;
	vector<vector<pair<int64_t,int64_t>>>adj(n);
	for (int64_t i = 0;i<m;++i){
		int64_t x,y,z;cin>>x>>y>>z;
		--x;--y;
		adj[x].push_back({y,z});
		adj[y].push_back({x,z});
	}
	const int64_t mxn = 1e18;
	priority_queue<pair<int64_t,pair<int64_t,int64_t>>>q;
	vector<vector<int64_t>>dist(n,vector<int64_t>(2,mxn));
	q.push({0,{U,0}});
	q.push({0,{V,1}});
	dist[U][0] = 0;
	dist[V][1] = 0;
	while(!q.empty()){
		auto u = q.top().second;
		q.pop();
		for (auto x:adj[u.first]){
			if (dist[x.first][u.second] > dist[u.first][u.second] + x.second){
				dist[x.first][u.second] = dist[u.first][u.second] + x.second;
				q.push({-dist[x.first][u.second],{x.first,u.second}});
			}
		}
	}
	int64_t ans = dist[U][1];
	vector<int64_t>dis(n,mxn);
	priority_queue<pair<long long,long long>>qs;
	qs.push({0,S});
	dis[S] = 0;
	vector<vector<int64_t>>dp(n,vector<int64_t>(4,mxn));
	while(!qs.empty()){
		auto u = qs.top();
		qs.pop();
		if (-u.first > dis[u.second])continue;
		for (auto x:adj[u.second]){
			if (dis[x.first] > dis[u.second] + x.second){
				dis[x.first] = dis[u.second] + x.second;
				qs.push({-dis[x.first],x.first});
			}
		}
	}
	dp[S][1] = dist[S][0];
	dp[S][2] = dist[S][1];
	vector<bool>visited(n,false);
	dp[S][3] = dist[S][0] + dist[S][1];
	auto bfs = [&](){
		set<int>qq;
		qq.insert(S);
		while(!qq.empty()){
			auto u = *qq.begin();
			qq.erase(qq.begin());
			visited[u] = true;
			for (auto x:adj[u]){
				if (dis[x.first] == dis[u] + x.second && !visited[x.first]){
					qq.insert(x.first);
					auto get = [&](int64_t v,int64_t j){
						int64_t res = 0;
						if (j & 1)res+=dist[v][0];
						if (j & 2)res+=dist[v][1];
						return res;
					};
					for (int i = 0;i < 4;++i){
						for (int j = 0;j<4;++j){
							dp[x.first][i | j] = min(dp[x.first][i | j],dp[u][i] + get(x.first,j));
						}
					}
				}
			}
		}
		ans = min(ans,dp[T][3]);
	};
	bfs();
	cout<<ans<<'\n';
	return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |