|
| 1 | +#include <cstdio> |
| 2 | +#include <algorithm> |
| 3 | +#include <cstring> |
| 4 | +#include <vector> |
| 5 | +#include <queue> |
| 6 | + |
| 7 | +#define MAXN 155 |
| 8 | +#define MAXV 510 |
| 9 | + |
| 10 | +#define INF 1234567890.0 |
| 11 | + |
| 12 | +#define X first |
| 13 | +#define Y second |
| 14 | +#define mp make_pair |
| 15 | +#define pb push_back |
| 16 | + |
| 17 | +using namespace std; |
| 18 | + |
| 19 | +typedef pair< int, int > pii; |
| 20 | +typedef pair< double, pii > node; |
| 21 | + |
| 22 | +double dist[ MAXN + 1 ][ MAXV + 1 ]; |
| 23 | + |
| 24 | +int N, M; |
| 25 | +pii choice[ MAXN + 1 ][ MAXV + 1 ]; |
| 26 | +vector< node > G[ MAXN + 1 ]; |
| 27 | + |
| 28 | +int readint() { |
| 29 | + int n = 0; |
| 30 | + char c = getchar_unlocked(); |
| 31 | + while ( !( '0' <= c && c <= '9' ) ) { |
| 32 | + c = getchar_unlocked(); |
| 33 | + } |
| 34 | + while ( '0' <= c && c <= '9' ) { |
| 35 | + n = n * 10 + c - '0'; |
| 36 | + c = getchar_unlocked(); |
| 37 | + } |
| 38 | + return n; |
| 39 | +} |
| 40 | + |
| 41 | +void init() { |
| 42 | + for( int i = 0; i <= MAXN; i++ ) { |
| 43 | + for( int j = 0; j <= MAXV; j++ ) { |
| 44 | + dist[ i ][ j ] = INF; |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +void dijkstra( int s ) { |
| 50 | + init(); |
| 51 | + priority_queue< node, vector<node>, greater<node> > Q; |
| 52 | + dist[ s ][ 70 ] = 0.0; |
| 53 | + choice[ s ][ 70 ] = mp( 0, 70 ); |
| 54 | + Q.push( mp( 0, mp( 0, 70 ) ) ); |
| 55 | + while( !Q.empty() ) { |
| 56 | + node A = Q.top(); |
| 57 | + Q.pop(); |
| 58 | + int u = A.Y.X, vel1 = A.Y.Y; |
| 59 | + double d = A.X; |
| 60 | + for( int i = 0; i < G[ u ].size(); i++ ) { |
| 61 | + int v = G[ u ][ i ].Y.X, vlim = G[ u ][ i ].Y.Y, myvel; |
| 62 | + double l = G[ u ][ i ].X, ans; |
| 63 | + if( vlim == 0 ) { |
| 64 | + myvel = vel1; |
| 65 | + } else { |
| 66 | + myvel = vlim; |
| 67 | + } |
| 68 | + ans = d + ( double )( ( double )l / ( double )myvel ); |
| 69 | + if( ans < dist[ v ][ myvel ] ) { |
| 70 | + dist[ v ][ myvel ] = ans; |
| 71 | + choice[ v ][ myvel ] = mp( u, vel1 ); |
| 72 | + Q.push( mp( ans, mp( v, myvel ) ) ); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +int main( void ) { |
| 79 | + int D; |
| 80 | + scanf("%d%d%d", &N, &M, &D ); |
| 81 | + for( int i = 0; i < M; i++ ) { |
| 82 | + int a, b, l, v; |
| 83 | + scanf("%d%d%d%d", &a, &b, &v, &l ); |
| 84 | + G[ a ].pb( mp( ( double )l, mp( b, v ) ) ); |
| 85 | + } |
| 86 | + dijkstra( 0 ); |
| 87 | + double ans = INF; |
| 88 | + int vel; |
| 89 | + for( int i = 0; i <= MAXV; i++ ) { |
| 90 | + if( dist[ D ][ i ] < ans ) { |
| 91 | + ans = dist[ D ][ i ]; |
| 92 | + vel = i; |
| 93 | + } |
| 94 | + } |
| 95 | + int t = D; |
| 96 | + vector< int > path; |
| 97 | + path.pb( t ); |
| 98 | + while( t > 0 ) { |
| 99 | + pii u = choice[ t ][ vel ]; |
| 100 | + path.pb( u.X ); |
| 101 | + t = u.X; |
| 102 | + vel = u.Y; |
| 103 | + } |
| 104 | + printf("%d", path[ path.size() - 1 ] ); |
| 105 | + for( int i = path.size() - 2; i >= 0; i-- ) { |
| 106 | + printf(" %d", path[ i ] ); |
| 107 | + } |
| 108 | + printf("\n"); |
| 109 | + return 0; |
| 110 | +} |
0 commit comments