이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///0-0 : what is your motivation, quan606303?
///quan606303 : Hutao
/*idea :
*/
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define file(a) freopen(a".inp","r",stdin); freopen(a".out","w",stdout);
using namespace std;
const int MOD=1e9+7;
const int maxn=1e5+7;
vector <pair<int,int> > adj[maxn];
int n,m,s,t,u,v,diS[maxn],diT[maxn],diU[maxn],diV[maxn];
void dijstra(int x,int *dis)
{
priority_queue<pair<int,int>,vector<pair<int,int> > ,greater<pair<int,int> > > q;
bool vst[maxn];
for (int i=1;i<=n;i++)
{
dis[i]=1e18;
vst[i]=false;
}
dis[x]=0;
q.push({0,x});
while (q.size())
{
int k=q.top().se;
q.pop();
// cout<<u<<endl;
if (vst[k])continue;
vst[k]=true;
for (auto i:adj[k])
{
if (dis[i.fi]>dis[k]+i.se)
{
dis[i.fi]=dis[k]+i.se;
q.push({dis[i.fi],i.fi});
}
}
}
}
int dp1[maxn],dp2[maxn];
vector <int> vt;
bool cmp(int x,int y)
{
return diS[x]<diS[y];
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//file("PathLib");
cin>>n>>m>>s>>t>>u>>v;
for(int i=1;i<=m;i++)
{
int x,y,w;
cin>>x>>y>>w;
adj[x].push_back({y,w});
adj[y].push_back({x,w});
}
dijstra(s,diS);
dijstra(t,diT);
dijstra(u,diU);
dijstra(v,diV);
for (int i=1;i<=n;i++)vt.push_back(i);
sort(vt.begin(),vt.end(),cmp);
// cout<<diS[4]<<" "<<diT[4]<<" "<<diS[t]<<endl;
int res=diU[v];
for (auto x:vt)
{
if (diS[x]+diT[x]==diS[t])
{
dp1[x]=diU[x];
dp2[x]=diV[x];
for (auto y:adj[x])
{
if(diS[y.fi] + y.se == diS[x]){
dp1[x]=min(dp1[x],dp1[y.fi]);
dp2[x]=min(dp2[x],dp2[y.fi]);
}
}
//cout<<x<<" "<<dp1[x]<<" "<<dp2[x]<<endl;
res = min({res, dp1[x] + diV[x], dp2[x] + diU[x]});
}
//cout<<res<<endl;
}
cout<<res;
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... |