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>
#define int long long
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 1;
const int oo = 1e18;
int n, m, S, T, U, V;
int c[N], w[N];
vector<pair<int,int>> adj[N];
struct mmb
{
int vertex, dlab;
bool operator < (const mmb& other) const
{
return dlab > other.dlab;
}
};
priority_queue<mmb> Q;
void DFS(int u,int par)
{
for(auto v : adj[u])
{
if(c[v.fi] + w[v.se] == c[u] && v.fi != par)
{
w[v.se] = 0;
DFS(v.fi, u);
}
}
}
void dijikstra1()
{
fill(c + 1, c + n + 1, oo);
c[S] = 0;
Q.push({S, 0});
while(!Q.empty())
{
auto o = Q.top(); Q.pop();
int u = o.vertex;
if(c[u] != o.dlab || u == T) continue;
for(auto v : adj[u])
{
if(c[u] + w[v.se] < c[v.fi])
{
c[v.fi] = c[u] + w[v.se];
Q.push({v.fi, c[v.fi]});
}
}
}
DFS(T, 0);
}
void dijikstra2()
{
while(!Q.empty()) Q.pop();
fill(c + 1, c + n + 1, oo);
c[U] = 0;
Q.push({U, 0});
while(!Q.empty())
{
auto o = Q.top(); Q.pop();
int u = o.vertex;
if(c[u] != o.dlab) continue;
if(u == V) break;
for(auto v : adj[u])
{
if(c[u] + w[v.se] < c[v.fi])
{
c[v.fi] = c[u] + w[v.se];
Q.push({v.fi, c[v.fi]});
}
}
}
}
int32_t main()
{
// freopen("test.inp", "r" ,stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
cin >> S >> T >> U >> V;
for(int i = 1; i <= m; i++)
{
int x, y, z;
cin >> x >> y >> z;
adj[x].push_back({y, i});
adj[y].push_back({x, i});
w[i] = z;
}
dijikstra1();
dijikstra2();
cout << c[V];
}
# | 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... |