#include #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep1(i, n) for(int i = 1; i <=(int)(n); i++) #define all(obj) (obj).begin(), (obj).end() typedef long long int ll; using namespace std; map, ll> mpc,mpt; ll ans = -1; int n,m; ll x; void dfs(int start,int goal, vector>& graph, vector&passed, ll cost, ll time){ if( start == goal){ ll atime = cost / x; if( cost % x != 0) atime++; if( ans == -1){ ans = atime+time; }else{ ans = min(ans,atime+time); } return ; } passed[start] = true; for( auto nx: graph[start]){ if( passed[nx] == false){ dfs(nx,goal,graph,passed, cost+mpc[{start,nx}], time+mpt[{start,nx}]); } } passed[start] = false; } int main() { cin >> n >> m >> x; vector> graph(n); rep(i,m){ int u,v; ll c,t; cin >> u >> v >> c >> t; v--; u--; mpt[{u,v}] = t; mpc[{u,v}] = c; mpt[{v,u}] = t; mpc[{v,u}] = c; graph[u].push_back(v); graph[v].push_back(u); } vector passed(n,false); ans = -1; dfs(0,n-1,graph,passed,0,0); cout << ans << endl; }