#include #include using namespace std; const long pinf = 1<<30; long heap[500005],poz[500005],d[500005]; long n,m,i,a,b; struct nod { long cost,val; nod *next; }*p,*l[500001]; void citire(long &n,long &k,long &a,long &b) { long x,y,i,j; nod *p; scanf("%ld%ld%ld%ld",&n,&k,&a,&b); for(i=1;ival=j; p->cost=b; p->next=l[i]; l[i]=p; p=new nod; p->val=i; p->cost=b; p->next=l[j]; l[j]=p; } for(i=1;i<=k;i++) { scanf("%ld%ld",&x,&y); for(p=l[x];p->val!=y;p=p->next); p->cost=a; for(p=l[y];p->val!=x;p=p->next); p->cost=a; } } void urca(long pozi) { while(pozi>1&& d[heap[pozi]]<=d[heap[pozi>>1]]) { swap(heap[pozi],heap[pozi>>1]); poz[heap[pozi]]=pozi; poz[heap[pozi>>1]]=pozi>>1; pozi/=2; } } void coboara(long pozi) { { long poz1=0; while(pozi!=poz1) { poz1=pozi; if((poz1<<1)<=n && d[heap[pozi]]>d[heap[poz1<<1]]) pozi=poz1<<1; if((poz1<<1)+1<=n && d[heap[pozi]]>d[heap[(poz1<<1)+1]]) pozi=(poz1<<1)+1; swap(heap[pozi],heap[poz1]); poz[heap[pozi]]=pozi; poz[heap[poz1]]=poz1; } }} int main() { citire(n,m,a,b); long ni=n,x; for(i=1;i<=n;i++) { d[i]=pinf; heap[i]=poz[i]=i; } d[1]=0; for(i=1;i<=ni;i++) { x=heap[1]; swap (heap[1],heap[n]); swap (poz[heap[1]],poz[heap[n]]); n--; coboara(1); for(p=l[x];p!=NULL;p=p->next) if(d[p->val]>d[x]+p->cost) { d[p->val]=d[x]+p->cost; urca(poz[p->val]); } } printf("%ld",d[ni]); return 0; }