#include #include #define MAXSIZE 500000 long n, k, auah, buah, i, x, y; typedef struct { long source; long destination; } pair; pair v[MAXSIZE]; long sol[MAXSIZE]; void init() { long i; for (i = 0;i < n;i++) sol[i] = buah; } void swap(long *x, long *y) { long t = *x; *x = *y; *y = t; } long partition( pair a[], long l, long r) { long pivot, i, j; pair t; pivot = a[l].source; i = l; j = r+1; while( 1) { do ++i; while( a[i].source <= pivot && i <= r ); do --j; while( a[j].source > pivot ); if( i >= j ) break; t = a[i]; a[i] = a[j]; a[j] = t; } t = a[l]; a[l] = a[j]; a[j] = t; return j; } void quickSort( pair a[], long l, long r) { long j; if( l < r ) { // divide and conquer j = partition( a, l, r); quickSort( a, l, j-1); quickSort( a, j+1, r); } } int main() { pair d; scanf("%ld%ld%ld%ld", &n, &k, &auah, &buah); init(); for (i = 0; i < k; i++) { scanf("%ld%ld", &x, &y); if (x > y) swap(&x, &y); d.source = x-1; d.destination = y-1; v[i] = d; } quickSort(v, 0, k-1); sol[0] = 0; for (i = 0; i < k; i++) { if (sol[v[i].source] + auah < sol[v[i].destination]) sol[v[i].destination] = sol[v[i].source] + auah; } printf("%ld\n", sol[n-1]); return 0; }