이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |