이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=2e5+5;
const ll offset=1e18;
const ll block_sz=317;
const ll inf=1e18;
const ll mod=1e9+7;
int n,u,v,s,t,m;
priority_queue<pii,vector<pii>,greater<pii>> pq;
vector<pii> adj1[maxn];
vector<int> adj[maxn];
vector<int> L;
int inu[maxn],inv[maxn],deg[maxn];
bool dd[maxn];
vector<int> disktra(int x)
{
vector<int> dist(n+1,inf);
dist[x]=0;
pq.push({0,x});
while (!pq.empty())
{
int u=pq.top().se;
int _=pq.top().fi;
pq.pop();
if (dist[u]!=_) continue;
for(auto [v,w]:adj1[u] )
{
if (dist[v]>dist[u]+w)
{
dist[v]=dist[u]+w;
pq.push({dist[v],v});
}
}
}
return dist;
}
void sol()
{
cin >> n>>m>>s>>t>>u>>v;
for1(i,1,m)
{
int a,b,c;cin >>a>>b>>c;
adj1[a].pb({b,c});
adj1[b].pb({a,c});
}
vector<int> Lu=disktra(u);
vector<int> Lv=disktra(v);
vector<int> Ls=disktra(s);
vector<int> Lt=disktra(t);
for1(x,1,n)
{
if (Ls[x]+Lt[x]==Ls[t])
{
// cerr<< x<<'\n';
dd[x]=true;
inu[x]=Lu[x];
inv[x]=Lv[x];
for(auto [y,w]: adj1[x])
{
if (dd[y])
{
if (Ls[y]+w==Ls[x])
{
deg[x]++;
adj[y].pb(x);
}
else if (Ls[y]==Ls[x]+w)
{
deg[y]++;
adj[x].pb(y);
}
}
}
}
}
// for1(i,1,n)
// {
// if (dd[i])
// {
// if (!adj[i].empty())cerr<< i<< ' '<< adj[i][0]<<'\n';
// }
// }
vector<int> qq;
int ans=Lu[v];
qq.pb(s);
while(!qq.empty())
{
int x=qq.back();
//cerr<< x<< '\n';
qq.pop_back();
ans=min(ans,min(inu[x]+Lv[x],inv[x]+Lu[x]));
//cerr << ans<<'\n';
for(int y:adj[x])
{
deg[y]--;
inu[y]=min(inu[y],inu[x]);
inv[y]=min(inv[y],inv[x]);
if (deg[y]==0)
{
qq.pb(y);
}
}
}
cout << ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("GROUPDIV.inp","r",stdin);
// freopen("GROUPDIV.out","w",stdout);
int t=1;//cin >> t;
while (t--)
{
sol();
}
}
# | 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... |