-
Notifications
You must be signed in to change notification settings - Fork 166
/
Investigation.cpp
60 lines (53 loc) · 1.5 KB
/
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,ll> edge;
typedef pair<ll,int> node;
const int maxN = 1e5+1;
const ll MOD = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f;
int N, M, a, b, minR[maxN], maxR[maxN];
ll c, dist[maxN], ways[maxN];
vector<edge> G[maxN];
struct Comparator {
bool operator() (int x, int y) const {
return dist[x] == dist[y] ? x < y : dist[x] < dist[y];
}
};
set<int, Comparator> PQ;
int main(){
scanf("%d %d", &N, &M);
memset(dist, 0x3f, sizeof(dist));
for(int i = 0; i < M; i++){
scanf("%d %d %lld", &a, &b, &c);
G[a].push_back({b, c});
}
PQ.insert(1);
ways[1] = 1;
dist[1] = 0;
while(!PQ.empty()){
int u = *PQ.begin();
ll d = dist[u];
PQ.erase(PQ.begin());
for(edge e : G[u]){
int v = e.first;
ll w = e.second;
if(d + w <= dist[v]){
if(dist[v] != INF) PQ.erase(v);
if(d + w == dist[v]){
ways[v] = (ways[u] + ways[v]) % MOD;
minR[v] = min(minR[v], minR[u]+1);
maxR[v] = max(maxR[v], maxR[u]+1);
}
if(d + w < dist[v]){
dist[v] = d+w;
ways[v] = ways[u];
minR[v] = minR[u]+1;
maxR[v] = maxR[u]+1;
}
PQ.insert(v);
}
}
}
printf("%lld %lld %d %d\n", dist[N], ways[N], minR[N], maxR[N]);
}