이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,m,s,t,u,v,x,y,z,i,dis[100001],ans=1e18;
vector<pair<ll,ll>> g[100001];
priority_queue<pair<ll,ll>> q;
map<pair<ll,ll>,bool> mp;
void ko(){
q.push({0,u});
memset(dis,-1,sizeof dis);
while(!q.empty()){
z=q.top().ff;
x=q.top().ss;
q.pop();
if(dis[x]!=-1) continue;
dis[x]=-z;
for(pair<ll,ll> i:g[x]){
if(dis[i.ff]==-1){
if(mp[{x,i.ff}]) q.push({z,i.ff});
else q.push({z-i.ss,i.ff});
}
}
}
ans=min(ans,dis[v]);
}
void dfs(ll x){
if(x==s){
ko();
return;
}
for(pair<ll,ll> i:g[x]){
if(dis[x]==dis[i.ff]+i.ss){
mp[{x,i.ff}]=1;
mp[{i.ff,x}]=1;
dfs(i.ff);
mp[{x,i.ff}]=0;
mp[{i.ff,x}]=0;
}
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m >> s >> t >> u >> v;
for(i=1;i<=m;i++){
cin >> x >> y >> z;
g[x].push_back({y,z});
g[y].push_back({x,z});
}
memset(dis,-1,sizeof dis);
q.push({0,s});
while(!q.empty()){
z=q.top().ff;
x=q.top().ss;
q.pop();
if(dis[x]!=-1) continue;
dis[x]=-z;
for(pair<ll,ll> i:g[x]){
if(dis[i.ff]==-1) q.push({z-i.ss,i.ff});
}
}
dfs(t);
cout << ans;
}
# | 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... |