1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include <iostream> #include <cstring> #include <algorithm> #include <queue> #include <unordered_map> #define endl '\n' #define int long long #define YES puts("YES") #define NO puts("NO") #define umap unordered_map #define INF 0x3f3f3f3f3f3f3f3f3f3f #define All(x) (x).begin(),(x).end() #pragma GCC optimize(3,"Ofast","inline") #define ___G std::ios::sync_with_stdio(false),cin.tie(0), cout.tie(0) using namespace std; const int N = 2e6 + 10;
int n,k,start,last;
int dist[N]; int spend[N]; bool st[N];
struct Edge { int b; int dis; int m; inline Edge(int _b,int _dis,int _m) { b = _b; dis = _dis; m = _m; } inline bool operator<(const Edge&w)const { if(dis != w.dis) return dis > w.dis; else return m > w.m; } };
int h[N],w[N],m[N],ne[N],e[N],idx; inline void Add(int a,int b,int c,int d) { e[idx] = b,w[idx] = c,m[idx] = d,ne[idx] = h[a],h[a] = idx++; }
inline void Dijkstra() { memset(dist,INF,sizeof dist); memset(spend,INF,sizeof spend); dist[start] = 0; spend[start] = 0; priority_queue<Edge>q; q.push(Edge(start,0,0)); while(q.size()) { Edge now = q.top(); q.pop(); int b = now.b; int dis = now.dis; int spe = now.m; if(st[b]) continue; st[b] = true; for(int i = h[b];i != -1;i = ne[i]) { int j = e[i]; if(dist[j] > dis + w[i]) { dist[j] = dis + w[i]; spend[j] = spe + m[i]; }else if(dist[j] == dis + w[i] && spend[j] > spe + m[i]) spend[j] = spe + m[i]; q.push(Edge(j,dist[j],spend[j])); } } }
inline void solve() { cin >> n >> k >> start >> last; while(k--) { int a,b,c,d; cin >> a >> b >> c >> d; Add(a,b,c,d); Add(b,a,c,d); } Dijkstra(); cout << dist[last] << ' ' << spend[last] << endl; } signed main() { memset(h,-1,sizeof h);
___G; int _t = 1;
while (_t--) { solve(); }
return 0; }
|