이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// clang-format off
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#define int long long
#define ll long long
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
const long long INF = 100000000000010;
const int inf = 1000000010;
const int maxn = 262144;
const int mxlg = 20;
const double eps = 1e-13;
int mod = 1e9 + 9;
const int C = 340;
vector<vector<pair<int, int>>> g;
struct reb{
int v, u, w;
};
int n;
vector<int> dij(int s) {
vector<int> d(n, INF);
d[s] = 0;
set<pair<int, int>> buf;
buf.insert({0, s});
while (!buf.empty()) {
int v = buf.begin()->second;
buf.erase(buf.begin());
for (auto [to, c]: g[v]) {
if (d[v] + c < d[to]) {
buf.erase({d[to], to});
d[to] = d[v] + c;
buf.insert({d[to], to});
}
}
}
return d;
}
vector<int> dij2(int s, set<pair<int, int>> &DAG) {
vector<int> d(n, INF);
d[s] = 0;
set<pair<int, int>> buf;
buf.insert({0, s});
while (!buf.empty()) {
int v = buf.begin()->second;
buf.erase(buf.begin());
for (auto [to, c]: g[v]) {
if(DAG.count({v, to}))c = 0;
if (d[v] + c < d[to]) {
buf.erase({d[to], to});
d[to] = d[v] + c;
buf.insert({d[to], to});
}
}
}
return d;
}
void solve() {
int m, s, t, v, u;
cin >> n >> m >> s >> t >> v >> u;
--s, --t, --v, --u;
g.resize(n);
vector<reb> eds(m);
for (int i = 0; i < m; ++i) {
int x, y, c;
cin >> x >> y >> c;
--x, --y;
eds[i] = {x, y, c};
g[x].push_back({y, c});
g[y].push_back({x, c});
}
vector<int> ds = dij(s);
vector<int> dt = dij(t);
set<pair<int, int>> DAG, DAG2;
for(auto[x, y, w]:eds){
if(ds[x] + w + dt[y] == ds[t]){
DAG.insert({x, y});
DAG2.insert({y, x});
}
if(ds[y] + w + dt[x] == ds[t]){
DAG.insert({y, x});
DAG2.insert({x, y});
}
}
vector<int> d = dij2(v, DAG);
vector<int> d2 = dij2(v,DAG2);
cout << min(d2[u], d[u]) << '\n';
}
signed main() {
// freopen("kthzero.in", "r", stdin);
// freopen("kthzero.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int __ = 1;
// cin >> __;
while (__--)
solve();
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... |