# CDOJ 1147 秋实大哥带我飞 最短路径条数 dijkstra就可搞

dijkstra时，我们是先更新离它最近的点，然后逐个点逐个点的搞，相当于只要是我们这次遍历到的点，它的最短路就已经求出来了，但是它也会往别的点上去更新，所以我们就可以记录它的最短路径数，并在它更新时，扩散出去

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <fstream>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000009
#define maxn 2005
#define maxm 4010
struct Edge
{
int next, to, w;
Edge() :next(0), to(0), w(0) { }
}edge[maxm];
void add(int u, int v, int w)
{
edge[cnt].w = w;
edge[cnt].to = v;
}
struct HeapNode
{
int dis, u;
bool operator <(const HeapNode& rhs)const
{
return (dis>rhs.dis) || (dis == rhs.dis&&u > rhs.u);
}
HeapNode()
{
dis = 0; u = 0;
}
HeapNode(int dis, int u)
{
this->dis = dis; this->u = u;
}
};
int dist[maxn], ways[maxn];
bool done[maxn];
void dijkstra(int s)
{
priority_queue<HeapNode> Q;
memset(dist, 0x3f, sizeof(int)*maxn);
memset(done, 0, sizeof(done));
memset(ways, 0, sizeof(int)*maxn);
dist[s] = 0;
ways[s] = 1;
Q.push(HeapNode(0, s));
while (!Q.empty())
{
HeapNode x = Q.top(); Q.pop();
int u = x.u;
if (done[u])
continue;
done[u] = true;
for (int i = head[u]; i != -1; i = edge[i].next)
{
int v = edge[i].to;
if (dist[v] > dist[u] + edge[i].w)
{
dist[v] = dist[u] + edge[i].w;
if (edge[i].w == 0)
ways[v] = -1;
else
ways[v] = ways[u];
Q.push(HeapNode(dist[v], v));
}
else if (dist[v] == dist[u] + edge[i].w)
{
if (edge[i].w == 0)
ways[v] = -1;
else
{
if (ways[u] == -1 || ways[v] == -1)
ways[v] = -1;
else
ways[v] = (ways[u] + ways[v]) % mod;
}
}
}
}
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
//ifstream in;
//in.open("input.txt", ios::in);
cnt = 0;
int n, m;
scanf("%d%d", &n, &m);
int s, e, c;
for (int i = 0; i < m; ++i)
{
scanf("%d%d%d", &s, &e, &c);
--s; --e;
}