forked from truongcongthanh2000/TrainACM-ICPC-OLP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cpp
120 lines (108 loc) · 3.15 KB
/
Test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <bits/stdc++.h>
using namespace std;
#define INP "solve"
#define OUT "solve"
const long long INF_LL = 1e17;
const int INF = 1e9 + 100;
const int MOD = 1e9 + 7;
const int Base = 30;
const double EPS = 1e-9;
const int BLOCK = 1000;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
void open_file() {
#ifdef THEMIS
freopen(INP ".inp","r",stdin);
freopen(OUT ".out","w",stdout);
#endif // THEMIS
}
const int maxN = 2e5 + 10;
typedef pair<int, int> i2;
typedef pair<long long, int> i2LL;
typedef pair<long long, i2> i3;
int n, m;
vector<i2> adj[maxN];
int numPath[maxN];
long long dist[2][maxN];
int numFlight[2][maxN];
bool Bigger(int a, int b) {
return a > b;
}
bool Weak(int a, int b) {
return a < b;
}
void Dijkstra(int S, bool compare(int, int), int baseNumFlight, long long dist[maxN], int numFlight[maxN]) {
priority_queue<i3, vector<i3>, greater<i3> > Q;
for (int i = 1; i <= n; i++) {
dist[i] = INF_LL;
numPath[i] = 0;
numFlight[i] = baseNumFlight;
}
dist[S] = 0;
numPath[S] = 1;
numFlight[S] = 0;
Q.push({0, {S, 0}});
while ((int)Q.size() != 0) {
i3 A = Q.top(); Q.pop();
long long du = A.first;
int u = A.second.first;
int nFlight = A.second.second;
if (du != dist[u]) continue;
if (numFlight[u] != nFlight) continue;
for (auto it : adj[u]) {
int v = it.first;
int w = it.second;
if (dist[v] > dist[u] + w) {
dist[v] = dist[u] + w;
numPath[v] = numPath[u];
numFlight[v] = numFlight[u] + 1;
Q.push({dist[v], {v, numFlight[v]}});
}
else {
if (dist[v] == dist[u] + w) {
numPath[v] = (numPath[u] + numPath[v]) % MOD;
if (compare(nFlight + 1, numFlight[v])) {
numFlight[v] = nFlight + 1;
Q.push({dist[v], {v, numFlight[v]}});
}
}
}
}
}
}
void sol() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
Dijkstra(1, Weak, INF, dist[0], numFlight[0]);
Dijkstra(n, Weak, INF, dist[1], numFlight[1]);
vector<int> res;
for (int i = 1; i <= n; i++) {
if (dist[0][i] + dist[1][i] != d || numFlight[0][i] + numFlight[1][i] != numF) res.push_back(i);
}
cout << (int)res.size() << '\n';
for (int x : res) cout << x << ' ';
}
void solve() {
int T;
///cin >> T;
T = 1;
int TestCase = 0;
while (T--) {
TestCase += 1;
//cout << "Case #" << TestCase << ":" << ' ';
///cout << "Case #" << TestCase << '\n';
sol();
}
}
int main(int argc,char *argv[]) {
//srand(time(nullptr));
ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
open_file();
solve();
}