Bzoj 2292 POJ Challenge Forever Challenge dijkstra__ Shortest path/shortest circuit number

Source: Internet
Author: User
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 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.