Skip to content

Commit 743f133

Browse files
committed
atcoder/abc192E
1 parent a4a21c5 commit 743f133

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

atcoder/abc192/E/main.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N, M, X, Y;
8+
vector<vector<array<int,3>>> G;
9+
10+
ll solve() {
11+
using entry = pair<ll,int>;
12+
priority_queue<entry, vector<entry>, greater<entry>> Q;
13+
ll const inf = 1e18;
14+
vector<ll> D(N, inf);
15+
Q.push({ 0, X });
16+
D[X] = 0;
17+
while (Q.size()) {
18+
ll t; int v;
19+
tie(t, v) = Q.top(); Q.pop();
20+
if (v == Y) {
21+
return t;
22+
}
23+
for (auto utk : G[v]) {
24+
int u = utk[0], T = utk[1], K = utk[2];
25+
ll tn = t;
26+
if (tn % K != 0) {
27+
tn += (K - tn % K);
28+
}
29+
if (tn + T < D[u]) {
30+
D[u] = tn + T;
31+
Q.push({ D[u], u });
32+
}
33+
}
34+
}
35+
return -1;
36+
}
37+
38+
int main() {
39+
ios_base::sync_with_stdio(false);
40+
cin.tie(0); cout.tie(0);
41+
42+
cin >> N >> M >> X >> Y;
43+
--X, --Y;
44+
45+
G.assign(N, vector<array<int,3>>());
46+
for (int i = 0; i < M; ++i) {
47+
int A, B, T, K;
48+
cin >> A >> B >> T >> K;
49+
--A, --B;
50+
G[A].push_back({ B, T, K });
51+
G[B].push_back({ A, T, K });
52+
}
53+
cout << solve() << endl;
54+
55+
return 0;
56+
}

0 commit comments

Comments
 (0)