이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
const int MAXN = 200005;
typedef pair<int, int> II;
int n, m, s, t, u, v, w[MAXN];
long long d[MAXN];
vector<II> g[MAXN], prv[MAXN];
set<II> q;
void dijk(int a, int b)
{
fill(d + 1, d + n + 1, LLONG_MAX);
q.clear();
q.insert(II(0, a));
d[a] = 0;
while (!q.empty())
{
int x = q.begin()->se;
q.erase(q.begin());
for (II node : g[x])
{
int y = node.fi, id = node.se;
if (d[y] > d[x] + w[id])
{
if (d[y] < LLONG_MAX)
q.erase(II(d[y], y));
prv[y].clear();
prv[y].push_back(II(x, id));
d[y] = d[x] + w[id];
q.insert(II(d[y], y));
}
else if (d[y] == d[x] + w[id])
prv[y].push_back(II(x, id));
}
}
}
bool clear[MAXN];
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> s >> t >> u >> v;
for (int i = 1; i <= m; ++i)
{
int a, b, c;
cin >> a >> b >> c;
w[i] = c;
g[a].push_back(II(b, i));
g[b].push_back(II(a, i));
}
dijk(s, t);
vector<int> T;
T.push_back(t);
fill(clear + 1, clear + n + 1, false);
while (!T.empty())
{
int i = T.back();
T.pop_back();
if (clear[i])
continue;
clear[i] = true;
for (II node : prv[i])
{
w[node.se] = 0;
T.push_back(node.fi);
}
}
dijk(u, v);
cout << d[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... |