This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<long long,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1000000000000000ll;
const db Inf = 1e20;
const db eps = 1e-9;
void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}
const int maxn = 100050;
int n, m, s, t, u, v, tot, pre[maxn], fr[maxn], e[maxn*2];
struct node{int to, id;};
vector<node> adj[maxn];
ll dist[maxn];
bool inq[maxn];
priority_queue<pii,vector<pii>,greater<pii> > pq;
void add_edge(int u, int v, int w)
{
e[++tot] = w;
adj[u].pb((struct node){v, tot});
adj[v].pb((struct node){u, tot});
}
void dijkstra(int s, int t)
{
pq.push(mp(0ll, s));
fo(i,1,n) dist[i] = INF;
dist[s] = 0;
while(!pq.empty())
{
int h = pq.top().se; pq.pop(); inq[h] = false;
for(auto p : adj[h])
{
int v = p.to, w = e[p.id];
if(dist[v] > dist[h] + w)
{
dist[v] = dist[h] + w;
pre[v] = p.id; fr[v] = h;
if(!inq[v]) inq[v] = true, pq.push(mp(dist[v], v));
}
}
}
}
inline void back_track(int t)
{
if(t == s) return;
e[pre[t]] = 0;
back_track(fr[t]);
}
void read(int &x)
{
x = 0; char c = '.';
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
}
int main()
{
#ifdef MPS
fp("1.in","r",stdin);
fp("1.out","w",stdout);
#endif
read(n); read(m);
read(s); read(t); read(u); read(v);
fo(i,1,m)
{
int u, v, w;
read(u); read(v); read(w);
add_edge(u, v, w);
}
dijkstra(s, t);
back_track(t);
dijkstra(u, v);
pf("%lld\n",dist[v]);
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... |