Submission #20346183
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, M, X, Y;
int A[101010], B[101010], T[101010], K[101010];
vector<pair<int, pair<int,int>>> E[101010];
//---------------------------------------------------------------------------------------------------
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int vis[101010];
ll D[101010];
ll dijk() {
rep(i, 0, N) D[i] = infl;
rep(i, 0, N) vis[i] = 0;
min_priority_queue<pair<ll, int>> que;
D[X] = 0;
que.push({ 0, X });
while (!que.empty()) {
auto q = que.top(); que.pop();
ll cst = q.first;
int cu = q.second;
if (cu == Y) return D[Y];
if (vis[cu]) continue;
vis[cu] = 1;
fore(p, E[cu]) {
int to = p.first;
int T = p.second.first;
int K = p.second.second;
ll cst2 = (cst + K - 1) / K * K + T;
if (chmin(D[to], cst2)) que.push({ D[to], to });
}
}
return -1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> M >> X >> Y;
X--; Y--;
rep(i, 0, M) {
cin >> A[i] >> B[i] >> T[i] >> K[i];
A[i]--; B[i]--;
E[A[i]].push_back({ B[i], {T[i], K[i]} });
E[B[i]].push_back({ A[i], {T[i], K[i]} });
}
ll ans = dijk();
cout << ans << endl;
}
Submission Info
| Submission Time |
|
| Task |
E - Train |
| User |
hamayanhamayan |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
2692 Byte |
| Status |
AC |
| Exec Time |
96 ms |
| Memory |
12540 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| All |
hand.txt, max_01.txt, random_01.txt, random_02.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| Case Name |
Status |
Exec Time |
Memory |
| hand.txt |
AC |
17 ms |
5928 KiB |
| max_01.txt |
AC |
96 ms |
11888 KiB |
| random_01.txt |
AC |
67 ms |
12540 KiB |
| random_02.txt |
AC |
49 ms |
10624 KiB |
| random_05.txt |
AC |
37 ms |
8656 KiB |
| random_06.txt |
AC |
34 ms |
8972 KiB |
| random_07.txt |
AC |
44 ms |
10844 KiB |
| random_08.txt |
AC |
42 ms |
10896 KiB |
| random_11.txt |
AC |
36 ms |
8640 KiB |
| random_12.txt |
AC |
36 ms |
8724 KiB |
| random_13.txt |
AC |
32 ms |
8336 KiB |
| random_14.txt |
AC |
41 ms |
9276 KiB |
| random_15.txt |
AC |
42 ms |
10272 KiB |
| random_16.txt |
AC |
34 ms |
9016 KiB |
| random_17.txt |
AC |
42 ms |
10564 KiB |
| random_18.txt |
AC |
28 ms |
8632 KiB |
| random_21.txt |
AC |
81 ms |
11848 KiB |
| random_22.txt |
AC |
85 ms |
11812 KiB |
| random_23.txt |
AC |
82 ms |
11812 KiB |
| random_24.txt |
AC |
82 ms |
11792 KiB |
| random_31.txt |
AC |
66 ms |
11568 KiB |
| random_32.txt |
AC |
61 ms |
11608 KiB |
| random_33.txt |
AC |
63 ms |
11640 KiB |
| random_34.txt |
AC |
65 ms |
11704 KiB |
| sample_01.txt |
AC |
7 ms |
5976 KiB |
| sample_02.txt |
AC |
8 ms |
6028 KiB |
| sample_03.txt |
AC |
5 ms |
5916 KiB |
| sample_04.txt |
AC |
10 ms |
5868 KiB |