이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fori(x,a,b) for (int x=a;x<=b;x++)
#define ford(x,a,b) for (int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);
const int maxn = 2e5 + 10;
int n,m,s,t,u,v;
vector<ii> ke[maxn];
vector<int> dij(int s)
{
vector<int> f(n+5,1e15);
priority_queue<ii,vector<ii>,greater<ii> > h;
f[s] = 0;
h.push({0,s});
while(!h.empty())
{
ii tg = h.top();
h.pop();
int umin = tg.se,dmin = tg.fi;
forv(v,ke[umin]) if(f[v.fi] > dmin + v.se)
{
f[v.fi] = dmin + v.se;
h.push({f[v.fi],v.fi});
}
}
return f;
}
// f[i] : dg di ngan nhat khi di toi uu tu u->i;
main()
{
//freopen("task.inp","r",stdin);
fasty;
cin>>n>>m;
cin>>s>>t>>u>>v;
fori(i,1,m)
{
int x,y,c;cin>>x>>y>>c;
ke[y].pb({x,c}),ke[x].pb({y,c});
}
vector<int> fs = dij(s);
vector<int> ft = dij(t);
vector<int> fu = dij(u);
vector<int> fv = dij(v);
int res = fu[v];
fori(i,0,1)
{
vector<int> d(n+5,1e15),f(n+5,1e15);
priority_queue<ii,vector<ii>,greater<ii> > h;
h.push({0,s});
d[s] = 0,f[s] = fu[s];
while(!h.empty())
{
int umin,dmin;
tie(dmin,umin) = h.top();
h.pop();
res = min(res,f[umin] + fv[umin]);
forv(v,ke[umin]) if(fs[v.fi]+ft[v.fi]==fs[t])
{
f[v.fi] = min({f[v.fi],f[umin],fu[umin]});
if(d[v.fi] > dmin + v.se)
{
d[v.fi] = dmin + v.se;
h.push({d[v.fi],v.fi});
}
}
}
swap(fu,fv);
}
cout<<res;
}
/*
chon 1 dg di ngan nhat tu s->t,cho tat cac canh tren dg di nay = 0
sao cho dg di ngan nhat tu u->v la MIN
*/
//https://oj.uz/problem/view/JOI18_commuter_pass
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main()
| ^~~~
# | 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... |