#pragma GCC target("avx,avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #include using namespace std; using ll = long long int; //// 任意長整数型 //namespace mp = boost::multiprecision; //using Bint = mp::cpp_int; struct Souko { ll to; ll a; ll b; }; void Solve(const vector>& edges, const ll limitTime, const ll currentTime, const ll goalSoukoIndex, const ll currentSoukoIndex, const ll currentYokanSize, const vector visited, ll &maxYokanSize) { if (goalSoukoIndex == currentSoukoIndex) { maxYokanSize = max(maxYokanSize, currentYokanSize); return; } const vector& currentSouko = edges[currentSoukoIndex]; for (int i = 0; i < currentSouko.size(); ++i) { ll nextSoukoIndex = currentSouko[i].to; ll nextTime = currentTime + currentSouko[i].a; ll nextYokanSize = min(currentYokanSize, currentSouko[i].b); if (limitTime < nextTime) { continue; } if (visited[nextSoukoIndex] == false) { vector nextVisited = visited; nextVisited[nextSoukoIndex] = true; Solve(edges, limitTime, nextTime, goalSoukoIndex, nextSoukoIndex, nextYokanSize, nextVisited, maxYokanSize); } } return; } int main() { //input int N, M, X; cin >> N >> M >> X; vector> edges(N + 1); for (int i = 0; i < M; ++i) { ll u, v, a, b; cin >> u >> v >> a >> b; Souko souko1; souko1.to = v; souko1.a = a; souko1.b = b; edges[u].push_back(souko1); Souko souko2; souko2.to = u; souko2.a = a; souko2.b = b; edges[v].push_back(souko2); } vector visited(N + 1); for (int i = 0; i < N + 1; ++i) { visited[i] = false; } visited[1] = true; ll ans = -1; Solve(edges, X, 0, N, 1, LLONG_MAX, visited, ans); //ans cout << ans << endl; return 0; }