이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100005
#define INF 1000000000000000
typedef pair<ll,ll> pii;
vector <pii> g[MAXN];
bool gotov[MAXN];
priority_queue <pii> pq;
int n,m;
void dijkstra(ll *d,int source)
{
for(int i = 0; i < MAXN; i++)d[i]=INF,gotov[i]=false;
d[source]=0;
pq.push({-d[source],source});
while(!pq.empty())
{
int v = pq.top().second;
pq.pop();
if(gotov[v])continue;
gotov[v]=1;
for(auto x:g[v])
{
int u = x.first;
int c = x.second;
if(d[u]>d[v]+c)d[u]=d[v]+c,pq.push({-d[u],u});
}
}
}
ll ds[MAXN];
ll dt[MAXN];
ll du[MAXN];
ll dv[MAXN];
ll d1[MAXN];
ll d2[MAXN];
int s,t;
void dijkstraa(ll *d,ll *dd)
{
for(int i = 0; i < MAXN; i++)gotov[i]=false,dd[i]=d[i],pq.push({-dd[i],i});
while(!pq.empty())
{
int v = pq.top().second;
pq.pop();
if(gotov[v])continue;
gotov[v]=1;
for(auto x:g[v])
{
int u = x.first;
int c = x.second;
if( ds[u]+c+dt[v]==ds[t] && dd[u]>dd[v])dd[u]=dd[v],pq.push({-dd[u],u});
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
int u,v;
cin >> n >> m >> s >> t >> u >> v;
for(int i = 0; i < m; i++)
{
int x,y,c;
cin >> x >> y >> c;
g[x].push_back({y,c});
g[y].push_back({x,c});
}
dijkstra(ds,s);
dijkstra(dt,t);
dijkstra(du,u);
dijkstra(dv,v);
dijkstraa(dv,d1);
dijkstraa(du,d2);
ll ans = INF;
for(int i = 1; i <= n; i++)
{
ans=min(ans,du[i]+d1[i]);
ans=min(ans,dv[i]+d2[i]);
}
cout << ans;
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... |