-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1202.cpp
56 lines (54 loc) · 1.32 KB
/
1202.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5, MOD = 1e9 + 7;
int n, m, cnt[N], minnum[N], maxnum[N];
ll dist[N];
vector<int> order;
vector<pair<int, int>> g[N];
priority_queue<pair<ll, int>> q;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1, u, v, w; i <= m; ++i) {
cin >> u >> v >> w;
g[u].emplace_back(v, w);
}
fill(dist + 1, dist + 1 + n, 1e18);
q.emplace(dist[1] = 0, 1);
while (!q.empty()) {
auto [du, u] = q.top(); q.pop();
du = -du;
if (du != dist[u]) continue;
order.emplace_back(u);
for (auto [v, w]: g[u]) {
if (dist[v] > du + w) {
dist[v] = du + w;
q.emplace(-dist[v], v);
}
}
}
reverse(order.begin(), order.end());
for (int u: order) {
if (u == n) {
cnt[u] = 1;
minnum[u] = maxnum[u] = 0;
} else {
cnt[u] = 0;
minnum[u] = +1e9;
maxnum[u] = -1e9;
}
for (auto [v, w]: g[u]) {
if (dist[v] == dist[u] + w) {
cnt[u] += cnt[v];
minnum[u] = min(minnum[u], minnum[v] + 1);
maxnum[u] = max(maxnum[u], maxnum[v] + 1);
if (cnt[u] >= MOD) {
cnt[u] -= MOD;
}
}
}
}
cout << dist[n] << " " << cnt[1] << " " << minnum[1] << " " << maxnum[1] << "\n";
return 0;
}