이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#define fi first
#define se second
#define endl '\n'
#define mp make_pair
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back
using namespace __gnu_pbds;
using namespace std;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
typedef long long ll;
#define pii pair<int,int>
long long readInt() {
bool minus1 = false;
long long result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus1 = true; else result = ch-'0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result*10 + (ch - '0');
}
if (minus1)
return -result;
else
return result;
}
#define ii pair<ll,ll>
struct edge {
int x, y;
ll c;
};
edge Q[MAXN];
ll dist[MAXN];
ll dp[MAXN];
ll dp2[MAXN];
ll dist2[MAXN];
vector <pii> adj[MAXN];
int n;
vector<ll> dijkstra(int s)
{
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > > pq;
vector<ll> d(n+5, ll(1e18));
pq.push(mp(0,s)); d[s] = 0;
while(!pq.empty())
{
ll dist=pq.top().fi; int u=pq.top().se; pq.pop();
for(ii x:adj[u])
{
ll d2 = dist + x.se;
if(d[x.fi] > d2)
{
d[x.fi] = d2;
pq.push(mp(d2, x.fi));
}
}
}
return d;
}
int main() {
#ifdef IZI_KATKA
assert(freopen("input", "r", stdin));
assert(freopen("output", "w", stdout));
#endif
n = readInt(); int m = readInt();
int s = readInt(), e = readInt();
int s2 = readInt(), e2 = readInt();
for (int i = 1; i <= m; i++) {
Q[i].x = readInt();
Q[i].y = readInt();
Q[i].c = readInt();
adj[Q[i].x].pb({Q[i].y, Q[i].c});
adj[Q[i].y].pb({Q[i].x, Q[i].c});
}
vector <ll> d1 = dijkstra(s2);
vector <ll> d2 = dijkstra(e2);
ll ans = d1[e2];
priority_queue<ii,vector<ii>,greater<ii> > pq;
for(int i=1;i<=n;i++) dist[i]=dist2[i]=dp[i]=dp2[i]=ll(1e18);
dist[s] = 0; dp[s] = d2[s]; pq.push(mp(0,s));
while(!pq.empty())
{
ll d=pq.top().fi; int u=pq.top().se; pq.pop(); ll pre = dp[u];
for(ii x:adj[u])
{
ll dt = d + x.se; int v = x.fi;
if(dist[v] > dt)
{
dp[v] = min(pre, d2[v]);
dist[v] = dt;
pq.push(mp(dt,v));
}
else if(dist[v] == dt)
{
dp[v] = min(dp[v], min(pre, d2[v]));
}
}
}
dist2[e] = 0; dp2[e] = d2[e]; pq.push(mp(0,e));
while(!pq.empty())
{
ll d=pq.top().fi; int u=pq.top().se; pq.pop(); ll pre = dp2[u];
for(ii x:adj[u])
{
ll dt = d + x.se; int v = x.fi;
if(dist2[v] > dt)
{
dp2[v] = min(pre, d2[v]);
dist2[v] = dt;
pq.push(mp(dt,v));
}
else if(dist2[v] == dt)
{
dp2[v] = min(dp2[v], min(pre, d2[v]));
}
}
}
ll shortestori = dist[e];
for(int i=1;i<=n;i++)
{
if(dist[i]+dist2[i]==shortestori)
{
ans = min(ans, min(dp[i], dp2[i]) + d1[i]);
}
}
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... |