結果

問題 No.2387 Yokan Factory
ユーザー hiroshi tamura
提出日時 2023-07-22 00:01:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 2,276 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 138,820 KB
実行使用メモリ 643,328 KB
最終ジャッジ日時 2024-09-22 01:24:46
合計ジャッジ時間 9,333 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 MLE * 1 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx,avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <memory>
#include <cstdlib>
#include <cstring>
#include <cmath>
//#include <boost/multiprecision/cpp_int.hpp>
#include <memory>



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<vector<Souko>>& edges, const ll limitTime, const ll currentTime, const int goalSoukoIndex, const int currentSoukoIndex, const int currentYokanSize, const vector<bool> visited, int &maxYokanSize)
{

	if (goalSoukoIndex == currentSoukoIndex) {
		maxYokanSize = max(maxYokanSize, currentYokanSize);
		return;
	}

	

	const vector<Souko>& 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) {
			vector<bool> 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<vector<Souko>> 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<bool> 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;
}
0