voiddijkstra(){ for (int i = 1; i <= n; i ++) dis[i] = 8e18; dis[1] = 0; q.push((node) { 0, 1 }); while (!q.empty()) { int u = q.top().pos; q.pop(); if (vis[u]) continue; vis[u] = true; for (int e = head[u]; e != 0; e = g[e].next) { int v = g[e].to; if (dis[v] > dis[u] + log2(g[e].w)) { dis[v] = dis[u] + log2(g[e].w); q.push((node) { dis[v], v }); pre[v] = u; pre_weight[v] = g[e].w; } } } }
signedmain(){ cin >> n >> m; for (int i = 1; i <= m; i ++) { int x, y, z; cin >> x >> y >> z; add_edge(x, y, z); if (z == 0) { cout << 0 << endl; return0; } } dijkstra(); int i = n; int ans = 1; while (pre[i] != 0) { ans = ans * pre_weight[i]; ans = ans % 9987; i = pre[i]; } cout << ans << endl; }