이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define fi first
#define sec second
const ll MOD = 998244353;
const ll N = 2e5 + 5;
const ll INF = 1e18;
vector<pii>adj[N];
ll dist[N], dist2[N];
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
// cin >> tc;
while(tc--){
ll n,m; cin >> n >> m;
ll s,t; cin >> s >> t;
ll u,v; cin >> u >> v;
for(int i=1;i<=m;i++){
ll a,b,w; cin >> a >> b >> w;
adj[a].pb({b,w});
adj[b].pb({a,w});
}
for(int i=1;i<=n;i++) dist[i] = dist2[i] = INF;
dist[s] = 0;
set<pii>st;
st.insert({dist[s], s});
while(!st.empty()){
auto x = *st.begin(); st.erase(x);
if(dist[x.sec] != x.fi) continue;
for(auto i : adj[x.sec]){
if(dist[i.fi] > dist[x.sec] + i.sec){
dist[i.fi] = dist[x.sec] + i.sec;
st.insert({dist[i.fi], i.fi});
}
}
}
ll cur = t;
while(cur != s){
for(auto i : adj[cur]){
if(dist[i.fi] == dist[cur] - i.sec){
i.sec = 0;
cur = i.fi;
break;
}
}
}
dist2[u] = 0;
st.insert({dist2[u], u});
while(!st.empty()){
auto x = *st.begin(); st.erase(x);
for(auto i : adj[x.sec]){
if(dist2[i.fi] > dist2[x.sec] + i.sec){
dist2[i.fi] = dist2[x.sec] + i.sec;
st.insert({dist2[i.fi], i.fi});
}
}
}
cout << dist2[v] << "\n";
}
}
/*
*/
# | 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... |