Title Link: http://poj.org/problem?id=3159
Test instructions: give n personal candy, give the M group of data, each group of data contains a,b,c three number, meaning a candy number than B less than the number of C, that is, B candy number-a candy number <= C.
The last to ask N than 1 more than the number of sweets.
Can be from the condition of the
B-a<=c and B<=a+c finally to achieve this condition is to be b>a+c when the b=a+c can
So it's almost the shortest way. There are some optimizations in this question, such as
if (Vis[u]) continue; This avoids duplicate lookups of U-Points
#include <iostream> #include <string> #include <cstring> #include <vector> #include <queue > #include <cstdio> #define INF 0x3f3f3f3fusing namespace std;const int m = 2e5;int N, m, A, B, C, dis[30010]; struct TnT {int u, V, W, next;} t[m];struct qnode{int V, c; Qnode (int v, int c): V (v), C (c) {} BOOL operator < (const qnode &R) const{return c > r.c; }};int head[30010], e;void Add (int u, int v, int w) {t[e].v = v; T[E].W = W; T[e].next = Head[u]; Head[u] = e++;} BOOL Vis[m];void dij (int s) {priority_queue<qnode>q; Memset (Vis, false, sizeof (VIS)); Q.push (Qnode (s, 0)); Dis[s] = 0; while (!q.empty ()) {int u = q.top (). V; Q.pop (); if (Vis[u]) continue; Vis[u] = true; for (int i = head[u]; i =-1; i = t[i].next) {int v = t[i].v, w = T[I].W; if (!vis[v] && dis[v] > Dis[u] + W) {Dis[v] = dIs[u] + W; Q.push (Qnode (V, Dis[v])); }}}}int Main () {while (scanf ("%d%d", &n, &m)! = EOF) {e = 0; for (int i = 1; I <= n; i++) {dis[i] = inf; Head[i] =-1; } for (int i = 1; I <= m; i++) {scanf ("%d%d%d", &a, &b, &c); Add (A, B, c); } dij (1); printf ("%d\n", Dis[n]); } return 0;}
Poj 3159 Candies (Dijstra optimized non-vector notation)