# 最短路

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 70006    Accepted Submission(s): 30590

Problem Description

Input

Output

Sample Input
2 1 1 2 3 3 3 1 2 5 2 3 5 3 1 2 0 0

Sample Output
3 2

Source

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int mapp[220][220];
int dis[220];
int n , m;
int s ,t;
struct Node
{
int st;
int  dd;
bool friend operator < (Node a , Node b)
{
return  a.dd > b.dd;
}
}pt , qt;
void dijkstra()
{
bool vis[1010] = {false};
priority_queue<Node >q;
dis[1] = 0;  // 起点要赋0  WA了一次
pt.st = 1;
pt.dd = 0;
q.push(pt);
while( ! q.empty())
{
pt = q.top();
q.pop();
if( vis[pt.st] )
continue;
vis[pt.st] = true;
for(int i = 2; i <= n; i++)
{
if(mapp[pt.st][i] != INF)
{
qt.st = i;
qt.dd = pt.dd + mapp[pt.st][i];
if(qt.dd < dis[qt.st])
{
dis[qt.st] = qt.dd;
q.push(qt);
}
}
}
}
}
int main()
{
while(~scanf("%d %d",&n,&m)&&(n || m))
{
memset(mapp , INF , sizeof(mapp));
memset(dis , INF , sizeof(dis));
for(int i = 0; i < m; i++)
{
int x, y ,z;
scanf("%d %d %d",&x,&y,&z);
mapp[x][y] = mapp[y][x] =  min( mapp[x][y] , z);
}
dijkstra();
printf("%d\n",dis[n]);
}
return 0;
}