이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
const int INF = 2147483645;
const int maxN = (int)1e5+5;
const ll LLINF = LLONG_MAX;
//const ll mod = 998244353;
const ll mod = 1000000007;
vector<pair<int, ll>> adj[maxN], adj2[maxN];
vector<ll> d, d2;
vector<int> p, p2;
int n;
void dijkstra(int s) {
d.assign(n+1, INF);
p.assign(n+1, -1);
d[s] = 0;
set<pair<int, int>> q;
q.insert({0, s});
while (!q.empty()) {
int v = q.begin()->second;
q.erase(q.begin());
for (auto edge : adj[v]) {
int to = edge.first;
int len = edge.second;
if (d[v] + len < d[to]) {
q.erase({d[to], to});
d[to] = d[v] + len;
p[to] = v;
q.insert({d[to], to});
}
}
}
}
void dijkstra2(int s) {
d2.assign(n+1, INF);
p2.assign(n+1, -1);
d2[s] = 0;
set<pair<int, int>> q;
q.insert({0, s});
while (!q.empty()) {
int v = q.begin()->second;
q.erase(q.begin());
for (auto edge : adj2[v]) {
int to = edge.first;
int len = edge.second;
if (d2[v] + len < d2[to]) {
q.erase({d2[to], to});
d2[to] = d2[v] + len;
p2[to] = v;
q.insert({d2[to], to});
}
}
}
}
vector<int> restore_path(int s, int t) {
vector<int> path;
for (int v = t; v != s; v = p[v])
path.push_back(v);
path.push_back(s);
reverse(path.begin(), path.end());
return path;
}
void solv() {
int m, s, t, u, v, a, b;
vector<pair<pii, ll>> vec;
ll c;
cin>>n>>m;
cin>>s>>t;
cin>>u>>v;
for (int i=0;i<m;i++) {
cin>>a>>b>>c;
vec.pb(mp(mp(a, b), c));
adj[a].pb(mp(b, c));
adj[b].pb(mp(a, c));
}
dijkstra(s);
vector<int> pth = restore_path(s, t);
map<int, int> chk;
int len = pth.size();
for (int i=0;i<len-1;i++) {
chk[pth[i]] = pth[i+1];
}
for (int i=0;i<m;i++) {
a = vec[i].first.first; b = vec[i].first.second; c = vec[i].second;
if (chk[a] == b || chk[b] == a) c = 0;
adj2[a].pb(mp(b, c));
adj2[b].pb(mp(a, c));
}
dijkstra2(u);
cout<<d2[v]<<'\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int t=1;
// cin>>t;
while (t--) solv();
}
| # | 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... |