Description
Lqp18_31 and 1tthinking often question to abuse Ftiasch. One day, lqp18_31 a direction map, each side of the length is 1. He wanted Ftiasch to find the shortest path of 1 points N. "Water problem ah." , Ftiasch said.
So 1tthinking increases the length of some edges by 1 (that is, the length of each edge is not 1 or 2). Now, poor Ftiasch will turn to you for help.
Input
Line 1th, two integers N (1≤n≤105) and M (1≤m≤106), number of points and sides.
2nd to M + 1 lines: Three integer UI, VI, WI (1≤wi≤2), from point Ui to Vi length for the side of WI.
Output
An integer that represents the shortest circuit point of 1 points N. Data guarantees that there is at least one path.
Sample Input
3 3
1 2 1
2 3 1
1 3 2
Sample Output 2
HINT
Transmission Door WOC ... Plus read all kinds of wa+tle ... Get rid of fast reading ... All Kinds of AC ...
Dij is 40 times times faster than SPFA, WOC.
#include <bits/stdc++.h> using namespace std;
int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |
Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}
while (ch>= ' 0 ' &&ch<= ' 9 ') {x= (x<<1) + (x<<3) +ch-' 0 '; Ch=getchar ();}
return x*f;
const int n=100005, m=1000005;
int ecnt,n,m;
int dist[n];
BOOL Vis[n];
struct Heap{int num,val;
#define QQ (A,B) (Heap) {a,b} priority_queue