[Explanations] CJOI2019 Trade (shortest + Nature)
How to evaluate CJ Huang, a high school players like mouth to the point of behavior?
Ten past eleven began to write ... This question is a little shy when someone urged me to finish winding up
【Problem Description】
\ (2020 \) years, the capitalist world's first \ (p \) times of financial crisis.
Far ends of the earth in a dish cooked country has also been some impact.
In order to accelerate the pace of economic development, the Government intends to reduce the country's large-scale local tariffs.
After the tariff reduction, with \ (x \) ten thousand yuan to reach a region, as long as the pay \ (1 \) tax million.
However, some areas of the Chief Executive to resist this directive, they announced that it will maintain the original tax, that is, with \ (x \) ten thousand yuan to reach these areas, need to pay \ (\ lceil \ frac {x } {k} \ rceil \ ) yuan tax.
Various regions throughout the country by the \ (m \) road link with each other.
Now I want to take money from a businessman \ (s \) to reach \ (t \) ground. He hoped that all paid the taxes to reach \ (t \) region, the total amount of money of not less than \ (w \) million. So please help him calculate, how much money he should bring a minimum of departure?
(Region do not need to \ (s \) tax)
Obviously from \ (T \) began to push back, due to the tax cuts out of the city very well, now is not the city tax cuts
Push back, adding turns out to be from \ (u-> v \) , and now I know \ (v \) weights, seeking \ (u \) is \ (dis \)
Solutions of about (X \) \ equation
\ [x- \ lceil \ dfrac xk
b \ \ rceil =] solution out
\ [x = \ lceil \ dfrac {kb} {k-1} \ rceil \]
Since \ (dis \) array will be monotonically increasing, it can be greedy dij
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(c<48||c>57)f|=c==45,c=getchar();
while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
const int maxn=5e5+5;
struct E{
int to,nx,w;
E(){to=nx=w=0;}
E(const int&a,const int&b,const int&c){to=a;nx=b;w=c;}
}e[maxn<<2];
int head[maxn];
int cnt;
int S,T,W;
int n,m,k;
int j[maxn];
inline void add(const int&fr,const int&to,const int&f){
int w=-1;
if(!j[fr]) w=k;
e[++cnt]=E(to,head[fr],w);
head[fr]=cnt;
if(f)add(to,fr,0);
}
ll d[maxn];
int last[maxn];
const ll inf=2e17;
typedef pair < ll , int > Pll;
priority_queue < Pll , vector < Pll > , greater < Pll > > q;
inline int getw(const ll&x,const ll&mu){
if(mu==-1)return x+1;
return (x*mu)/(mu-1LL)+bool((x*mu)%(mu-1));
}
inline int spfa(){
for(register int t=1;t<=n;++t) d[t]=inf;
d[T]=W;
q.push(make_pair(d[T],T));
while(q.size()){
register auto now=q.top();
q.pop();
if(now.second==S)break;
for(register int t=head[now.second],t1;t;t=e[t].nx){
t1=getw(d[now.second],e[t].w);
if(d[e[t].to]>t1){
d[e[t].to]=t1;
last[e[t].to]=now.second;
q.push(make_pair(d[e[t].to],e[t].to));
}
}
}
return d[S];
}
int main(){
//freopen("trade.in","r",stdin);
//freopen("trade.out","w",stdout);
n=qr();m=qr();k=qr();
for(register int t=1;t<=n;++t) j[t]=qr();
for(register int t=1;t<=m;++t) add(qr(),qr(),1);
S=qr();T=qr();W=qr();
printf("%d\n%d",spfa(),S);
for(register int t=last[S];t;t=last[t])
printf("->%d",t);
return 0;
}