#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 { int to; int a; int b; }; void Solve(const vector>& edges, const ll& limitTime, const ll& currentTime, const int& goalSoukoIndex, const int& currentSoukoIndex, const int& currentYokanSize, vector& visited, int &maxYokanSize) { if (goalSoukoIndex == currentSoukoIndex) { maxYokanSize = max(maxYokanSize, currentYokanSize); return; } const vector& currentSouko = edges[currentSoukoIndex]; for (int i = 0; i < currentSouko.size(); ++i) { int nextSoukoIndex = currentSouko[i].to; ll nextTime = currentTime + currentSouko[i].a; int nextYokanSize = min(currentYokanSize, currentSouko[i].b); if (limitTime < nextTime) { continue; } if (visited[nextSoukoIndex] == false) { visited[nextSoukoIndex] = true; Solve(edges, limitTime, nextTime, goalSoukoIndex, nextSoukoIndex, nextYokanSize, visited, maxYokanSize); visited[nextSoukoIndex] = false; } } return; } int main() { //input int N, M, X; cin >> N >> M >> X; vector> edges(N + 1); for (int i = 0; i < M; ++i) { int 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; int ans = -1; Solve(edges, X, 0, N, 1, INT_MAX, visited, ans); //ans cout << ans << endl; return 0; }