-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1202-investigation.cpp
81 lines (66 loc) · 1.99 KB
/
1202-investigation.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define umap unordered_map
#define uset unordered_set
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
const long long LLINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 5;
vector<pii> adj[MAX_N];
long long dist[MAX_N];
int ways[MAX_N], min_stops[MAX_N], max_stops[MAX_N];
void dijkstra(int s) {
fill(dist, dist + MAX_N, LLINF);
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
pq.push({dist[s] = 0, s});
ways[0] = 1;
while (!pq.empty()) {
auto [d, u] = pq.top(); pq.pop();
if (d > dist[u]) continue;
for (auto [v, w] : adj[u]) {
if (dist[v] > dist[u] + w) {
dist[v] = dist[u] + w;
pq.push({dist[v], v});
ways[v] = ways[u];
min_stops[v] = min_stops[u] + 1;
max_stops[v] = max_stops[u] + 1;
} else if (dist[v] == dist[u] + w) {
ways[v] += ways[u];
if (ways[v] >= MOD) ways[v] -= MOD;
min_stops[v] = min(min_stops[v], min_stops[u] + 1);
max_stops[v] = max(max_stops[v], max_stops[u] + 1);
}
}
}
}
void solve() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int from, to, price;
cin >> from >> to >> price;
from--; to--;
adj[from].pb({to, price});
}
dijkstra(0);
cout << dist[n - 1] << " " << ways[n - 1] << " " << min_stops[n - 1] << " " << max_stops[n - 1] << "\n";
}
int main() {
fastio
int tc = 1; // Number of test cases
// cin >> tc;
while (tc--) {
solve();
}
return 0;
}