/**
* author: mamion
* created: Sunday 2024-10-27
**/
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include<cpp-dump-main/cpp-dump.hpp>
#define debug(...) cpp_dump(__VA_ARGS__)
CPP_DUMP_SET_OPTION_GLOBAL(max_line_width, 100);
CPP_DUMP_SET_OPTION_GLOBAL(log_label_func, cpp_dump::log_label::filename());
CPP_DUMP_SET_OPTION_GLOBAL(enable_asterisk, true);
#else
#define debug(...)
#endif // LOCAL
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf = 1e9;
const int N = 1e4 + 10, M = 1e3 + 10;
int numNode, numEdge, moneyLim;
vector<tuple<int, int, int>> adj[N];
int f[N][M][2];
void dijkstra() {
memset(f, 0x3f, sizeof f);
f[1][moneyLim][0] = f[1][moneyLim][1] = 0;
priority_queue<tuple<int, int, int, int>> pq;
pq.push({0, 1, moneyLim, 0}); pq.push({0, 1, moneyLim, 1});
while (pq.size()) {
int dist = -get<0>(pq.top()); int u = get<1>(pq.top());
int money = get<2>(pq.top()); int state = get<3>(pq.top());
pq.pop();
if (dist != f[u][money][state]) continue;
for (auto p : adj[u]) {
int v = get<0>(p), c = get<1>(p), d = get<2>(p);
if (state == 1) c++; else d++;
// go by bike here
int moneyBike = money, wBike = 0;
if (moneyBike < c) {
moneyBike = min(moneyLim, money + (c - money + 99 - 1) / 99 * 99);
wBike = (c - money + 99 - 1) / 99;
}
moneyBike -= c;
if (f[v][moneyBike][0] > f[u][money][state] + wBike + c) {
f[v][moneyBike][0] = f[u][money][state] + wBike + c;
pq.push({-f[v][moneyBike][0], v, moneyBike, 0});
}
// go by bus here
int moneyBus = money, wBus = 0;
if (moneyBus < d) {
moneyBus = min(moneyLim, money + (d - money + 99 - 1) / 99 * 99);
wBus = (d - money + 99 - 1) / 99;
}
moneyBus -= d;
if (f[v][moneyBus][1] > f[u][money][state] + wBus + d) {
f[v][moneyBus][1] = f[u][money][state] + wBus + d;
pq.push({-f[v][moneyBus][1], v, moneyBus, 1});
}
}
}
}
void solve() {
cin >> numNode >> numEdge;
for (int i = 0; i < numEdge; i++) {
int u, v, c, d; cin >> u >> v >> c >> d;
adj[u].push_back({v, c, d});
adj[v].push_back({u, c, d});
}
cin >> moneyLim;
dijkstra();
int ans = inf;
for (int i = 0; i <= moneyLim; i++) {
ans = min(ans, f[numNode][i][0]);
ans = min(ans, f[numNode][i][1]);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
#else
#define file "name"
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
#endif // LOCAL
int T; T = 1; if (0) cin >> T;
for (int i = 1; i <= T; i++)
{
solve();
}
}
LyoqCiAqICAgIGF1dGhvcjogIG1hbWlvbgogKiAgICBjcmVhdGVkOiBTdW5kYXkgMjAyNC0xMC0yNwoqKi8KCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojaWZkZWYgTE9DQUwKI2luY2x1ZGU8Y3BwLWR1bXAtbWFpbi9jcHAtZHVtcC5ocHA+CiNkZWZpbmUgZGVidWcoLi4uKSBjcHBfZHVtcChfX1ZBX0FSR1NfXykKQ1BQX0RVTVBfU0VUX09QVElPTl9HTE9CQUwobWF4X2xpbmVfd2lkdGgsIDEwMCk7CkNQUF9EVU1QX1NFVF9PUFRJT05fR0xPQkFMKGxvZ19sYWJlbF9mdW5jLCBjcHBfZHVtcDo6bG9nX2xhYmVsOjpmaWxlbmFtZSgpKTsKQ1BQX0RVTVBfU0VUX09QVElPTl9HTE9CQUwoZW5hYmxlX2FzdGVyaXNrLCB0cnVlKTsKI2Vsc2UKI2RlZmluZSBkZWJ1ZyguLi4pCiNlbmRpZiAvLyBMT0NBTAoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgdW5zaWduZWQgbG9uZyBsb25nIHVs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W9uZXlCaWtlIDwgYykgewogICAgICAgICAgICAgICAgbW9uZXlCaWtlID0gbWluKG1vbmV5TGltLCBtb25leSArIChjIC0gbW9uZXkgKyA5OSAtIDEpIC8gOTkgKiA5OSk7CiAgICAgICAgICAgICAgICB3QmlrZSA9IChjIC0gbW9uZXkgKyA5OSAtIDEpIC8gOTk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbW9uZXlCaWtlIC09IGM7CiAgICAgICAgICAgIGlmIChmW3ZdW21vbmV5QmlrZV1bMF0gPiBmW3VdW21vbmV5XVtzdGF0ZV0gKyB3QmlrZSArIGMpIHsKICAgICAgICAgICAgICAgIGZbdl1bbW9uZXlCaWtlXVswXSA9IGZbdV1bbW9uZXldW3N0YXRlXSArIHdCaWtlICsgYzsKICAgICAgICAgICAgICAgIHBxLnB1c2goey1mW3ZdW21vbmV5QmlrZV1bMF0sIHYsIG1vbmV5QmlrZSwgMH0pOwogICAgICAgICAgICB9CgogICAgICAgICAgICAvLyBnbyBieSBidXMgaGVyZQogICAgICAgICAgICBpbnQgbW9uZXlCdXMgPSBtb25leSwgd0J1cyA9IDA7CiAgICAgICAgICAgIGlmIChtb25leUJ1cyA8IGQpIHsKICAgICAgICAgICAgICAgIG1vbmV5QnVzID0gbWluKG1vbmV5TGltLCBtb25leSArIChkIC0gbW9uZXkgKyA5OSAtIDEpIC8gOTkgKiA5OSk7CiAgICAgICAgICAgICAgICB3QnVzID0gKGQgLSBtb25leSArIDk5IC0gMSkgLyA5OTsKICAgICAgICAgICAgfQogICAgICAgICAgICBtb25leUJ1cyAtPSBkOwogICAgICAgICAgICBpZiAoZlt2XVttb25leUJ1c11bMV0gPiBmW3VdW21vbmV5XVtzdGF0ZV0gKyB3QnVzICsgZCkgewogICAgICAgICAgICAgICAgZlt2XVttb25leUJ1c11bMV0gPSBmW3VdW21vbmV5XVtzdGF0ZV0gKyB3QnVzICsgZDsKICAgICAgICAgICAgICAgIHBxLnB1c2goey1mW3ZdW21vbmV5QnVzXVsxXSwgdiwgbW9uZXlCdXMsIDF9KTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQoKdm9pZCBzb2x2ZSgpIHsKICAgIGNpbiA+PiBudW1Ob2RlID4+IG51bUVkZ2U7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG51bUVkZ2U7IGkrKykgewogICAgICAgIGludCB1LCB2LCBjLCBkOyBjaW4gPj4gdSA+PiB2ID4+IGMgPj4gZDsKICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHt2LCBjLCBkfSk7CiAgICAgICAgYWRqW3ZdLnB1c2hfYmFjayh7dSwgYywgZH0pOwogICAgfQogICAgY2luID4+IG1vbmV5TGltOwogICAgZGlqa3N0cmEoKTsKICAgIGludCBhbnMgPSBpbmY7CiAgICBmb3IgKGludCBpID0gMDsgaSA8PSBtb25leUxpbTsgaSsrKSB7CiAgICAgICAgYW5zID0gbWluKGFucywgZltudW1Ob2RlXVtpXVswXSk7CiAgICAgICAgYW5zID0gbWluKGFucywgZltudW1Ob2RlXVtpXVsxXSk7CiAgICB9CiAgICBjb3V0IDw8IGFuczsKfQoKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKCiNpZmRlZiBMT0NBTAogICAgZnJlb3BlbigibWFpbi5pbnAiLCAiciIsIHN0ZGluKTsKICAgIGZyZW9wZW4oIm1haW4ub3V0IiwgInciLCBzdGRvdXQpOwojZWxzZQogICAgI2RlZmluZSBmaWxlICJuYW1lIgogICAgaWYgKGZvcGVuKGZpbGUiLmlucCIsICJyIikpIHsKICAgICAgICBmcmVvcGVuKGZpbGUiLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oZmlsZSIub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQojZW5kaWYgLy8gTE9DQUwKCiAgICBpbnQgVDsgVCA9IDE7IGlmICgwKSBjaW4gPj4gVDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IFQ7IGkrKykKICAgIHsKICAgICAgICBzb2x2ZSgpOwogICAgfQp9Cg==