1, test instructions: Dijkstra template problem, save point template
#include <queue> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm >using namespace std; #define M 2000010#define inf 1047483647 inline int read () {char ch = getchar (); int x = 0, F = 1; while (Ch < ' 0 ' | | ch > ' 9 ') {if (ch = = '-') f =-1; ch = getchar (); } while (' 0 ' <= ch && ch <= ' 9 ') {x = x * + ch-' 0 '; ch = getchar (); } return x * f;} namespace dijkstra{struct node{int d, u; inline BOOL operator < (const node& RHS) const{return d > rhs.d; } }; int d[m], done[m]; Priority_queue<node> Q; struct edge{int U, V, W, next; } G[m]; int head[m], tot; int n; Number of points inline void init () {memset (head,-1, sizeof (head)); tot =-1; } inline void Add (int u, int v, int w) {g[++ tot] = (Edge) {u, V, W, Head[u]}; Head[u] = tot; } INLine void Get_dis (int s) {for (int i = 1; I <= n; i + +) d[i] = inf; D[s] = 0; while (! Q.empty ()) Q.pop (); Q.push (Node) {0, S}); memset (done, 0, sizeof (done)); while (! Q.empty ()) {Node u = q.top (); Q.pop (); int x = U.U; if (done[x]) continue; DONE[X] = 1; for (int i = head[x]; i =-1; i = g[i].next) {edge& e = g[i]; if (D[E.V] > D[x] + e.w) {D[E.V] = d[x] + e.w; Q.push (Node) {d[e.v], e.v}); }}}}} using namespace Dijkstra; int main () {n = read (); int m = read (); Init (); for (int i = 1; I <= m; i + +) {int u = read (), V = Read (), w = read (); Add (U, V, W); } get_dis (1); printf ("%d\n", D[n]); return 0;}
bzoj2292--"POJ Challenge" forever challenge