Problem:
Problem F:
Marching Course
Since members of Kitafuji High School Brass Band Club succeeded in convincing their stern
coach of their playing skills, they will be able to participate in Moon Light Festival as a marching
band. This festival is a prelude in terms of appealing their presence for the coming domestic
contest. Hence, they want to attract a festival audience by their performance.
Although this festival restricts performance time up to $P$ minutes, each team can freely determine
their performance course from a provided area. The provided area consists of $N$ checkpoints,
numbered 1 through $N$, and $M$ bidirectional roads connecting two checkpoints. Kitafuji Brass
Band already has the information about each road: its length and the expected number of people
on its roadside. Each team must start at the checkpoint 1, and return back to the checkpoint
1 in $P$ minutes. In order to show the performance ability of Kitafuji Brass Band to a festival
audience, their stern coach would like to determine their performance course so that many people
listen their march as long as possible.
The coach uses "impression degree" to determine their best course. If they play $m$ minutes on
the road with length $d$ and the expected number $v$ of people, then the impression degree will be
$m \times v/d$. The impression degree of a course is the sum of impression degree of their performance
on the course. Marching bands must move at a constant speed during marching: 1 unit length
per 1 minute. On the other hand, they can turn in the opposite direction at any time, any place
including a point on a road. The impression degree is accumulated even if they pass the same
interval two or more times.
Your task is to write a program to determine a course with the maximum impression degree in
order to show the performance ability of Kitafuji Brass Band to an audience as much as possible.
Input
The input is formatted as follows.
$N$ $M$ $P$
$s_1$ $t_1$ $d_1$ $v_1$
: : :
$s_M$ $t_M$ $d_M$ $v_M$
The first line contains three integers $N$, $M$, and $P$: the number of checkpoints $N$ ($2 \leq N \leq
200$), the number of roads $M$ ($N - 1 \leq M \leq N(N - 1)/2$), and the performance time $P$
($1 \leq P \leq 1,000$). The following $M$ lines represent the information about roads. The $i$-th line
of them contains four integers $s_i$, $t_i$, $d_i$, and $v_i$: the $i$-th road bidirectionally connects between
checkpoints $s_i$ and $t_i$ ($1 \leq s_i, t_i \leq N, s_i \ne t_i$) with length $d_i$ ($1 \leq d_i \leq 1,000$) and the expected
number $v_i$ ($1 \leq v_i \leq 1,000$) of people.
You can assume that any two checkpoints are directly or indirectly connected with one or more
roads. You can also assume that there are no pair of roads having the same pair of endpoints.
Output
Output the maximum impression degree of a course for a $P$-minute performance. The absolute
error should be less than $10^{-4}$.
Sample Input
3 3 4
1 2 1 1
2 3 2 4
3 1 1 1
Output for the Sample Input
6
Sample I
...(truncated)

Submitted solutions:

code_snippet: #include<bits/stdc++.h>

#define clr(x,y) memset((x),(y),sizeof(x))

using namespace std;
typedef long long LL;

const int INF = 1000000000;
const int maxn = 200 + 10;

struct Edge {
  int to,dist,v;
};


vector <Edge> G[maxn+5];
double dp[maxn+5][1005];
bool vis[maxn+5][1005];

double DP(int x,int time)
{
    if (vis[x][time]) return dp[x][time];

    double& ans=dp[x][time];
    vis[x][time]=1;
    ans=0;

    for (int i=0;i<G[x].size();++i)
    {
        Edge& e=G[x][i];
        ans=max(ans,time*1.0*e.v/e.dist);
        if (time>e.dist)
        {
            ans=max(ans,DP(e.to,time-e.dist)+e.v);
        }
    }
    return ans;
}

int main(void)
{
	#ifdef ex
	freopen ("../in.txt","r",stdin);
	//freopen ("../out.txt","w",stdout);
	#endif

	int n,m,p;
	scanf("%d%d%d",&n,&m,&p);

	int s,t,d,v;
	for (int i=1;i<=m;++i)
    {
        scanf("%d%d%d%d",&s,&t,&d,&v);
        d*=2;
        v*=2;
        G[s].push_back((Edge){t,d,v});
        G[t].push_back((Edge){s,d,v});
    }

    clr(vis,0);
    double ans=DP(1,p);
    printf("%.13f\n",ans);
}
accuracy: 1
time_ms: 60
memory_kb: 6052
final_rank: 10

code_snippet: // https://vjudge.ppsucdtt.cn/problem/Aizu-2722
// QwQ
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>

using namespace std;

const int N=210,M=1010;

int n,m,k;
double f[N][M];
double w[N];

struct Data{
	int a,b;
	bool operator<(const Data W)const{
		return b>W.b;
	}
}d[N][N];
priority_queue<Data> q;

int main(){
	scanf("%d%d%d",&n,&m,&k);
	double res=0;
	
	for(int i=1;i<=n;i++)
		for(int j=0;j<=k;j++)
			f[i][j]=-1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			d[i][j].a=1;

	for(int i=0;i<m;++i){
		int a,b,c,_d;
		scanf("%d%d%d%d",&a,&b,&c,&_d);
		c*=2;
		d[a][b]={c,_d};
		d[a][b]={c,_d};
	}

	for(int i=1;i<=n;++i){
		double dis=0;
		for(int j=1;j<=n;++j)
			dis=max(dis,d[i][j].b*1.0/d[i][j].a);
		w[i]=dis;
	}

	q.push({1,0});
	f[1][0]=0;
	res=w[1]*k;
// 	while(q.size()){
// 		Data t=q.top();
// 		q.pop();
// 		res=mad(res,f[t.a][t.b]+(k-t.b)*w[t.a]);
// 		for(int i=1;i<=n;++i){
// 			if(d[t.a][i].b == 0) continue;
// 			if(t.b+d[t.a][i].a <= k)
// 				if(f[t.a][t.b]+d[t.a][i].b > f[i][t.b+d[t.a][i].a]){
// 					if(f[i][t.b+d[t.a][i].a] == -1) 
// 						q.push({i,t.b+d[t.a][i].a});
// 					f[i][t.b+d[t.a][i].a]=f[t.a][t.b]+d[t.a][i].b;
// 				}
// 		}
// 	}
	while(!q.empty()){
		Data fr=q.top();
		q.pop();
		res=max(res,f[fr.a][fr.b]+(k-fr.b)*w[fr.a]);
		for(int i=1;i<=n;++i){
			if(d[fr.a][i].b==0)
				continue;
			if(fr.b+d[fr.a][i].a<=k){
				if(f[fr.a][fr.b]+d[fr.a][i].b>f[i][fr.b+d[fr.a][i].a]){ //剪枝啊
					if(f[i][fr.b+d[fr.a][i].a]==-1) //剪枝啊
						q.push({i,fr.b+d[fr.a][i].a});
					f[i][fr.b+d[fr.a][i].a]=f[fr.a][fr.b]+d[fr.a][i].b;
				}
			}
		}
	}
	printf("%.7lf",res*2);
	return 0;
}
accuracy: 0.1346153846153846
time_ms: 10
memory_kb: 5188
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    // Step 1. Input
    int N, M, P; cin >> N >> M >> P;
    vector<int> S(M, 0);
    vector<int> T(M, 0);
    vector<int> D(M, 0);
    vector<int> V(M, 0);
    for (int i = 0; i < M; i++) cin >> S[i] >> T[i] >> D[i] >> V[i];

    // Step 2. Prepare
    vector<double> maxv(N + 1, 0.0);
    for (int i = 0; i < M; i++) maxv[S[i]] = max(maxv[S[i]], 1.0 * V[i] / D[i]);
    for (int i = 0; i < M; i++) maxv[T[i]] = max(maxv[T[i]], 1.0 * V[i] / D[i]);

    // Step 3. Dynamic Programming
    vector<vector<double>> dp(P + 1, vector<double>(N + 1, -1.0e9));
    dp[0][1] = 0.0;
    for (int t = 0; t < P; t++) {
        for (int i = 1; i <= N; i++) dp[t + 1][i] = max(dp[t + 1][i], dp[t][i] + maxv[i]);
        for (int i = 0; i < M; i++) {
            if (t + D[i] > P) continue;
            dp[t + D[i]][T[i]] = max(dp[t + D[i]][T[i]], dp[t][S[i]] + V[i]);
            dp[t + D[i]][S[i]] = max(dp[t + D[i]][S[i]], dp[t][T[i]] + V[i]);
        }
    }

    // Step 4. Output
    printf("%.12lf\n", dp[P][1]);
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5456
final_rank: 7

code_snippet: // AOJ #2722
// Marching Course 2025.2.11

#include <bits/stdc++.h>
using namespace std;
 
const double NEG_INF = -1e12;
 
struct Edge { int to, d, v; };
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, M, P;
    cin >> N >> M >> P;
    
    vector<vector<Edge>> graph(N+1);
    vector<double> stall(N+1, 0.0);
    
    for (int i = 0; i < M; i++){
        int s, t, d, v;
        cin >> s >> t >> d >> v;
        graph[s].push_back({t, d, v});
        graph[t].push_back({s, d, v});
        double rate = (double)v / d;
        stall[s] = max(stall[s], rate);
        stall[t] = max(stall[t], rate);
    }
    
    vector<vector<double>> dp(N+1, vector<double>(P+1, NEG_INF));
    dp[1][0] = 0;
    
    for (int t = 0; t <= P; t++){
        for (int u = 1; u <= N; u++){
            if(dp[u][t] == NEG_INF) continue;
            for (auto &edge : graph[u]){
                int nt = t + edge.d;
                if(nt <= P){
                    dp[edge.to][nt] = max(dp[edge.to][nt], dp[u][t] + edge.v);
                }
            }
        }
    }
    
    double ans = dp[1][P];
    
    for (int i = 1; i <= N; i++){
        vector<double> f(P+1, NEG_INF);
        for (int t = 0; t <= P; t++){
            if(dp[i][t] > NEG_INF/2){
                f[t] = dp[i][t] - t * stall[i];
            }
        }
        vector<double> best(P+1, NEG_INF);
        best[0] = f[0];
        for (int t = 1; t <= P; t++){
            best[t] = max(best[t-1], f[t]);
        }
        double bestCandidate = NEG_INF;
        for (int t1 = 0; t1 <= P; t1++){
            if(f[t1] == NEG_INF) continue;
            double cand = f[t1] + best[P - t1];
            bestCandidate = max(bestCandidate, cand);
        }
        if(bestCandidate > NEG_INF/2)
            ans = max(ans, bestCandidate + P * stall[i]);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 5316
final_rank: 9

code_snippet: // AOJ #2722
// Marching Course 2025.2.11

#include <bits/stdc++.h>
using namespace std;
 
const double NEG_INF = -1e12;
 
struct Edge { int to, d, v; };
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, M, P;
    cin >> N >> M >> P;
    
    vector<vector<Edge>> graph(N+1);
    
    vector<double> stall(N+1, 0.0);
    for (int i = 0; i < M; i++){
        int s, t, d, v;
        cin >> s >> t >> d >> v;
        graph[s].push_back({t, d, v});
        graph[t].push_back({s, d, v});
        double rate = (double)v / d;
        stall[s] = max(stall[s], rate);
        stall[t] = max(stall[t], rate);
    }
    
    vector<vector<double>> dp(N+1, vector<double>(P+1, NEG_INF));
    dp[1][0] = 0;
    
    for (int t = 0; t <= P; t++){
        for (int u = 1; u <= N; u++){
            if(dp[u][t] == NEG_INF) continue;
            for (auto &edge : graph[u]){
                int nt = t + edge.d;
                if(nt <= P){
                    dp[edge.to][nt] = max(dp[edge.to][nt], dp[u][t] + edge.v);
                }
            }
        }
    }
    
    vector<vector<pair<int,double>>> valid(N+1);
    for (int i = 1; i <= N; i++){
        for (int t = 0; t <= P; t++){
            if(dp[i][t] > NEG_INF/2) {
                valid[i].push_back({t, dp[i][t]});
            }
        }
    }
    
    double ans = NEG_INF;
    ans = max(ans, dp[1][P]);
    
    for (int i = 1; i <= N; i++){
        if(valid[i].empty()) continue;
        int sz = valid[i].size();
        for (int a = 0; a < sz; a++){
            for (int b = 0; b < sz; b++){
                int timeUsed = valid[i][a].first + valid[i][b].first;
                if(timeUsed <= P){
                    double candidate = valid[i][a].second + valid[i][b].second;
                    candidate += (P - timeUsed) * stall[i];
                    ans = max(ans, candidate);
                }
            }
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 8456
final_rank: 18

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

struct Edge {
    int T, D, V;
};

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int N, M, P;
    cin >> N >> M >> P;
    int MAXS = P/2;
    vector<vector<Edge>> G(N);
    rep(i,0,M) {
        int s,t,d,v;
        cin >> s >> t >> d >> v;
        s--, t--;
        G[s].push_back({t,d,v});
        G[t].push_back({s,d,v});
    }
    vector<vector<ll>> DP(N, vector<ll>(MAXS+1, -INF));
    DP[0][0] = 0;
    rep(j,0,MAXS+1) {
        rep(i,0,N) {
            if (DP[i][j] < 0) continue;
            for (Edge E : G[i]) {
                if (j + E.D <= MAXS) chmax(DP[E.T][j+E.D], DP[i][j] + E.V);
            }
        }
    }
    double ANS = 0;
    rep(i,0,N) {
        double X = 0.0;
        for (Edge E : G[i]) {
            chmax(X, (double)E.V / (double)E.D);
        }
        rep(j,0,MAXS+1) {
            if (DP[i][j] < 0) continue;
            chmax(ANS, (double)DP[i][j] * 2 + X * (double)(P-j*2));
        }
    }
    printf("%.12f\n", ANS);
}
accuracy: 1
time_ms: 50
memory_kb: 4828
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rng(i, l, r) for(int i = int(l); i < int(r); i++)
#define rep(i, n) rng(i, 0, n)
#define sz(v) int(v.size())
#define foa(s, v) for(auto& s : v)
#define all(v) v.begin(), v.end()

template <class T>
bool chmax(T& a, T b) {
	return a < b ? a = b, 1 : 0;
}

template <class T>
bool chmin(T& a, T b) {
	return a > b ? a = b, 1 : 0;
}

int n;
void solve() {
	int m, p;
	cin >> m >> p;
	vector<vector<tuple<int, int, ll>>> g(n);  // adj, time, value;
	using ld = long double;
	vector<ld> waiting(n, 0);

	auto add_edge = [&](int s, int t, int len, ll value) -> void {
		g[s].emplace_back(t, len, value);
		chmax(waiting[s], ld(value) / ld(len));

		swap(s, t);

		g[s].emplace_back(t, len, value);
		chmax(waiting[s], ld(value) / ld(len));
	};

	constexpr ll INF = 1e15;

	rep(j, m) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		int time;
		ll val;
		cin >> time >> val;
		add_edge(s, t, time, val);
	}

	const int half = p / 2;
	vector<vector<ll>> dp((half + 1), vector<ll>((n), -INF));

	constexpr int start = 0;
	dp[0][start] = 0;

	ld ans = 0.;

	rep(consumed, half + 1) rep(ver, n) {
		const int remain_time = p - consumed * 2;
		ll res = dp[consumed][ver];

		for(auto [nxt, len, val] : g[ver]) {
			int nxt_c = consumed + len;
			if(nxt_c > half) continue;
			chmax(dp[nxt_c][nxt], res + val);
		}

		chmax(ans, ld(res) * 2 + waiting[ver] * ld(remain_time));
	}

	cout << ans << endl;
}
int main() {
	cout << fixed << setprecision(15);
	while(cin >> n && n) solve();
}
accuracy: 1
time_ms: 70
memory_kb: 5080
final_rank: 5

code_snippet: //#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000003;;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

struct edge {
	int to, d, v;
};

ld dp[200][1001];

void solve() {
	int n, m, p; cin >> n >> m >> p;
	vector<vector<edge>> G(n);
	rep(i, m) {
		int a, b, d, v; cin >> a >> b >> d >> v; a--; b--;
		G[a].push_back({ b,d,v });
		G[b].push_back({ a,d,v });
	}
	rep(i, n)rep(j, p + 1) {
		dp[i][j] = -INF;
	}
	dp[0][0] = 0;
	rep(j, p) {
		rep(i, n) {
			ld ma = 0;
			for (edge e : G[i]) {
				ma = max(ma, e.v / (ld)e.d);
				int ni = e.to;
				int nj = j + e.d;
				if (nj > p)continue;
				dp[ni][nj] = max(dp[ni][nj], dp[i][j] + e.v);
			}
			//if (i == 0)cout << ma << "\n";
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + ma);
			/*for (int nj = j + 1; nj <= p; nj++) {
				dp[i][nj] = max(dp[i][nj], dp[i][j] + (nj - j) * ma);
			}*/
		}
	}
	cout << dp[0][p] << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(8);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)
	//while(cin>>n>>q,n)
	solve();
	return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 7172
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=205,INF=1<<29;

int d[MAX][MAX],v[MAX][MAX];
int dp[1005][MAX];
double ma[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,P;cin>>N>>M>>P;
    for(int i=0;i<M;i++){
        int a,b,x,y;cin>>a>>b>>x>>y;
        a--;b--;
        d[a][b]=x;
        d[b][a]=x;
        v[a][b]=y;
        v[b][a]=y;
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(d[i][j]) chmax(ma[i],double(v[i][j])/d[i][j]);
        }
    }
    
    for(int i=0;i<=P;i++) for(int j=0;j<N;j++) dp[i][j]=-INF;
    dp[0][0]=0;
    
    double ans=0;
    
    for(int t=0;t<=P;t++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(d[i][j]==0) continue;
                if(t+d[i][j]<=P) chmax(dp[t+d[i][j]][j],dp[t][i]+v[i][j]);
            }
            if(t*2<=P) chmax(ans,dp[t][i]*2+ma[i]*(P-t*2));
        }
    }
    
    cout<<fixed<<setprecision(25)<<ans<<endl;
}
accuracy: 1
time_ms: 200
memory_kb: 4616
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=205,INF=1<<29;

int d[MAX][MAX],v[MAX][MAX];
int dp[1005][MAX];
double ma[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,P;cin>>N>>M>>P;
    for(int i=0;i<M;i++){
        int a,b,x,y;cin>>a>>b>>x>>y;
        a--;b--;
        d[a][b]=x;
        v[a][b]=y;
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(d[i][j]) chmax(ma[i],double(v[i][j])/d[i][j]);
        }
    }
    
    for(int i=0;i<=P;i++) for(int j=0;j<N;j++) dp[i][j]=-INF;
    dp[0][0]=0;
    
    double ans=0;
    
    for(int t=0;t<=P;t++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(d[i][j]==0) continue;
                if(t+d[i][j]<=P) chmax(dp[t+d[i][j]][j],dp[t][i]+v[i][j]);
            }
            if(t*2<=P) chmax(ans,dp[t][i]*2+ma[i]*(P-t*2));
        }
    }
    
    cout<<fixed<<setprecision(25)<<ans<<endl;
}
accuracy: 0.1346153846153846
time_ms: 40
memory_kb: 4352
final_rank: 19

code_snippet: // https://vjudge.ppsucdtt.cn/problem/Aizu-2722
// QwQ
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>

using namespace std;

const int N=210,M=1010;

int n,m,k;
double f[N][M];
double w[N];

struct Data{
	int a,b;
	bool operator<(const Data W)const{
		return b>W.b;
	}
}d[N][N];
priority_queue<Data> q;

int main(){
	scanf("%d%d%d",&n,&m,&k);
	double res=0;
	
	for(int i=1;i<=n;i++)
		for(int j=0;j<=k;j++)
			f[i][j]=-1;   
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)	
			d[i][j].a=1;
	for(int i=0;i<m;++i){
	    int a,b,c,_d;
	    scanf("%d%d%d%d",&a,&b,&c,&_d);
		c*=2;
		d[a][b]={c,_d};
		d[b][a]={c,_d};
	} 

	for(int i=1;i<=n;++i){
		double dis=0;
		for(int j=1;j<=n;++j)
			dis=max(dis,d[i][j].b*1.0/d[i][j].a);
		w[i]=dis;
	}

	q.push({1,0});
	f[1][0]=0;
	res=w[1]*k;
	while(q.size()){
		Data t=q.top();
		q.pop();
		res=max(res,f[t.a][t.b]+(k-t.b)*w[t.a]);
		for(int i=1;i<=n;++i){
			if(d[t.a][i].b == 0) continue;
			if(t.b+d[t.a][i].a <= k)
				if(f[t.a][t.b]+d[t.a][i].b > f[i][t.b+d[t.a][i].a]){
					if(f[i][t.b+d[t.a][i].a] == -1) 
						q.push({i,t.b+d[t.a][i].a});
					f[i][t.b+d[t.a][i].a]=f[t.a][t.b]+d[t.a][i].b;
				}
		}
	}

	printf("%.7lf",res*2);
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 5812
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
const double INF = 10000000;
int main(){
  cout << fixed << setprecision(20);
  int N, M, P;
  cin >> N >> M >> P;
  vector<vector<tuple<int, int, int>>> E(N);
  for (int i = 0; i < M; i++){
    int s, t, d, v;
    cin >> s >> t >> d >> v;
    s--;
    t--;
    E[s].push_back(make_tuple(d, v, t));
    E[t].push_back(make_tuple(d, v, s));
  }
  vector<vector<int>> dp(P + 1, vector<int>(N, -INF));
  dp[0][0] = 0;
  for (int i = 0; i < P; i++){
    for (int j = 0; j < N; j++){
      for (auto e : E[j]){
        int d = get<0>(e);
        int c = get<1>(e);
        int w = get<2>(e);
        if (i + d <= P){
          dp[i + d][w] = max(dp[i + d][w], dp[i][j] + c);
        }
      }
    }
  }
  double ans = 0;
  for (int i = 0; i < N; i++){
    double p = 0;
    for (auto e : E[i]){
      p = max(p, (double) get<1>(e) / get<0>(e));
    }
    vector<double> A(P + 1);
    for (int j = 0; j <= P; j++){
      A[j] = dp[j][i] - p * j;
    }
    double mx = -INF;
    for (int j = 0; j <= P; j++){
      mx = max(mx, A[j]);
      ans = max(ans, A[P - j] + mx + p * P);
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 4968
final_rank: 8

code_snippet: #include <iostream>
#include <iomanip>
#include <vector>
#include <tuple>

using namespace std;
using ldouble = long double;

constexpr int INF = 1 << 30;

void solve() {
    int n, m, p;
    cin >> n >> m >> p;

    vector<vector<tuple<int, int, int>>> graph(n);
    while (m--) {
        int u, v, d, c;
        cin >> u >> v >> d >> c;
        --u, --v;

        graph[u].emplace_back(v, d, c);
        graph[v].emplace_back(u, d, c);
    }

    auto dp = vector(n, vector(p + 1, -INF));
    dp[0][0] = 0;
    for (int x = 0; x < p; ++x) {
        for (int v = 0; v < n; ++v) {
            for (auto [u, d, c] : graph[v]) {
                if (x + d <= p) {
                    dp[u][x + d] = max(dp[u][x + d], dp[v][x] + c);
                }
            }
        }
    }

    ldouble ans = 0;
    for (int v = 0; v < n; ++v) {
        ldouble pmax = 0;
        for (auto [u, d, c] : graph[v]) {
            pmax = max(pmax, ldouble(c) / d);
        }

        for (int x = 0; x * 2 <= p; ++x) {
            ans = max(ans, dp[v][x] * 2 + pmax * (p - x * 2));
        }
    }

    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    solve();

    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 4672
final_rank: 4

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> M >> K;
	vector<vector<long double>>dp(N, vector<long double>(K + 1, -MOD));
	dp[0][0] = 0;
	vector<vector<int>>length(N, vector<int>(N));
	vector<vector<int>>gain(N, vector<int>(N));
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> H >> W;
		L--, R--;
		length[L][R] = H;
		length[R][L] = H;
		gain[R][L] = W;
		gain[L][R] = W;
	}
	vector<long double>stay(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (length[i][j]) {
				stay[i] = max(stay[i], (long double)1 * gain[i][j] / length[i][j]);
			}
		}
	}
	for (int i = 0; i < K; i++) {
		for (int j = 0; j < N; j++) {
			dp[j][i + 1] = max(dp[j][i + 1], dp[j][i] + stay[j]);
			for (int k = 0; k < N; k++) {
				if (length[j][k] && i + length[j][k] <= K) {
					dp[k][i + length[j][k]] = max(dp[k][i + length[j][k]], dp[j][i] + gain[j][k]);
				}
			}
		}
	}
	cout << setprecision(20) << dp[0].back() << endl;
}
accuracy: 1
time_ms: 190
memory_kb: 6404
final_rank: 14

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200

struct Edge{
	Edge(int arg_to,double arg_length,double arg_people,double arg_value){
		to = arg_to;
		length = arg_length;
		people = arg_people;
		value = arg_value;
	}
	int to;
	double length,people,value;
};

struct Info{
	Info(int arg_node_id,double arg_sum_cost){

		node_id = arg_node_id;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct Info &arg) const{
		return sum_cost > arg.sum_cost;
	}
	int node_id;
	double sum_cost;
};

int V,E;
double P,min_cost[NUM];
vector<Edge> G[NUM];

int main(){

	scanf("%d %d %lf",&V,&E,&P);

	int from,to;
	double length,people;

	for(int loop = 0; loop < E; loop++){

		scanf("%d %d %lf %lf",&from,&to,&length,&people);
		from--;
		to--;
		G[from].push_back(Edge(to,length,people,people/length));
		G[to].push_back(Edge(from,length,people,people/length));
	}

	double ans = 0,base_value,base_sum;
	int start = 0;

	priority_queue<Info> Q;
	int next_node;
	double next_cost,tmp_length,tmp_people;

	for(int base_node = 0; base_node < V; base_node++){

		base_value = 0;
		for(int i = 0; i < G[base_node].size(); i++){
			base_value = max(base_value,G[base_node][i].value);
		}

		base_sum = base_value*(P/2);

		for(int i = 0; i < V; i++)min_cost[i] = (double)BIG_NUM;
		min_cost[start] = 0;

		while(!Q.empty())Q.pop();

		Q.push(Info(start,0));

		while(!Q.empty()){

			if(Q.top().node_id == base_node){
				break;
			}else if(Q.top().sum_cost > min_cost[Q.top().node_id]){
				Q.pop();
			}else{

				for(int i = 0; i < G[Q.top().node_id].size(); i++){

					if(G[Q.top().node_id][i].value >= base_value)continue;

					next_node = G[Q.top().node_id][i].to;
					tmp_length = G[Q.top().node_id][i].length;
					tmp_people = G[Q.top().node_id][i].people;
					next_cost = Q.top().sum_cost+(base_value*tmp_length-tmp_people);

					if(min_cost[next_node] > next_cost){

						min_cost[next_node] = next_cost;
						Q.push(Info(next_node,next_cost));
					}
				}
				Q.pop();
			}
		}
		ans = max(ans,base_sum-min_cost[base_node]);
	}

	printf("%.10lf\n",2*ans);

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4776
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int N = 200;
int D[N][N], V[N][N];

double max_r[N];

const int P = 1010;
double dp[N][P][2];

int main(){
    memset(D,-1,sizeof(D));
    memset(V,-1,sizeof(V));

    int n,m,p;
    scanf(" %d %d %d", &n, &m, &p);

    rep(i,m){
        int s,t,d,v;
        scanf(" %d %d %d %d", &s, &t, &d, &v);
        --s;
        --t;

        D[s][t] = D[t][s] = d;
        V[s][t] = V[t][s] = v;
    }

    rep(i,n){
        rep(j,n)if(D[i][j]!=-1){
            max_r[i] = max(max_r[i], (double)V[i][j]/D[i][j]);
        }
    }

    rep(i,N)rep(j,P)rep(k,2) dp[i][j][k] = -123456789;
    dp[0][0][0] = 0;
    rep(t,p+1){
        rep(v,n){
            rep(f,2){
                // 移動
                rep(nx,n)if(D[v][nx]!=-1){
                    int nt = t+D[v][nx];
                    if(nt<=p) dp[nx][nt][f] = max(dp[nx][nt][f], dp[v][t][f]+V[v][nx]);
                }
            }

            // うろうろ
            rep(a,p+1){
                int nt = t+a;
                if(nt>p) break;
                dp[v][nt][1] = max(dp[v][nt][1], dp[v][t][0]+max_r[v]*a);
            }
        }
    }

    printf("%.10f\n", dp[0][p][1]);
    return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 6696
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const double INF=1e12;

int N,M,P;
int A[111111],B[111111],L[111111];
double C[111111];

double dp[1111][222];
double x[222];

signed main(){
    cin>>N>>M>>P;
    rep(i,M){
        cin>>A[i*2]>>B[i*2];
        A[i*2]--;B[i*2]--;
        int x,y;
        cin>>x>>y;
        C[i*2]=1.0*y/x;
        L[i*2]=x;

        A[i*2+1]=B[i*2];
        B[i*2+1]=A[i*2];
        C[i*2+1]=C[i*2];
        L[i*2+1]=L[i*2];
    }
    M*=2;

    fill_n(*dp,1111*222,-INF);
    dp[0][0]=0;
    for(int i=0;i<P;i++){
        for(int j=0;j<M;j++){
            if(i+L[j]>P)continue;
            chmax(dp[i+L[j]][B[j]],dp[i][A[j]]+L[j]*C[j]);
        }
    }

    rep(i,M)chmax(x[A[i]],C[i]);

    double ans=0;
    rep(i,N){
        for(int j=0;j<=P;j++){
            for(int k=0;j+k<=P;k++){
                chmax(ans,dp[j][i]+dp[k][i]+(P-j-k)*x[i]);
            }
        }
    }
    printf("%.20f\n",ans);
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 6364
final_rank: 16

code_snippet: #include<iostream>
#include<queue>
#include<vector>
#include<iomanip>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef double D;
typedef pair<D,int> pdi;
 
struct edge{
  D d,v;
  int to;
  edge(D a=0,D b=0,int c=0):d(a),v(b),to(c){}
  bool operator<(edge a)const{
    return d/v > a.d/a.v;
  }
};
 
int main(){
  int n,m;
  D d;
 
  while(cin >> n >> m >> d){
    if(n==0)break;
 
    vector< vector<edge> > g(n); 
    rep(i,m){
      int s,t;
      D dis, num;
      cin >> s >> t >> dis >> num; s--; t--;
      g[s].push_back( edge(dis,num,t) );
      g[t].push_back( edge(dis,num,s) );
    }
 
    D res = 0;
    rep(i,n){
      D maxv = 0;
      for(edge e : g[i])maxv = max(maxv, e.v/e.d);
 
      vector<D> dis(n,1e15);
      dis[0] = 0;
      priority_queue< pdi, vector<pdi>, greater<pdi> > q;
      q.push( pdi(0,0) );
 
      while(q.size()){
	pdi p = q.top(); q.pop();
	D cost = p.first, cur = p.second;
	if(dis[cur]+1e-8 < cost)continue;
 
	for(edge e : g[cur]){
	  D cospa = e.v/e.d;
	  if(cospa > maxv+1e-8)continue;
	  D ncost = cost + (maxv-cospa)*e.d;
	  if(dis[e.to] > ncost + 1e-8){
	    dis[e.to] = ncost;
	    q.push( pdi(ncost,e.to) );
	  }
	}
      }
 
      res = max(res, maxv*d - 2*dis[i]);
    }
 
    cout << fixed << setprecision(10) << res << endl;
  }
}
accuracy: 1
time_ms: 60
memory_kb: 4488
final_rank: 2

code_snippet: #include<bits/stdc++.h>
#define MAX_P 1020
#define MAX_V 220
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-15)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

class edge{
  public:
    int to,d,v;
    edge(int to,int d,int v):to(to),d(d),v(v){}
};

int n,m,p;
vector<edge> e[MAX_V];
double dp[MAX_V][MAX_P];

double solve(){
  double res=0.0;
  FOR(i,0,n)FOR(j,0,p+1)dp[i][j]=-1;
  dp[0][0]=0;
  FOR(i,0,p+1){
    FOR(j,0,n){
      if(dp[j][i]==-1)continue;
      FOR(k,0,e[j].size()){
        edge E=e[j][k];
        int t=min(E.d,p-i);
        int d=t+i;
        dp[E.to][d]=max(dp[E.to][d],dp[j][i]+(double)t*E.v/E.d);
      }
    }
  }
  FOR(i,0,n)res=max(res,dp[i][p]);
  return res*2.0;
}

int main()
{
  cin>>n>>m>>p;
  FOR(i,0,m){
    int s,t,d,v;
    cin>>s>>t>>d>>v;
    s--;t--;d*=2;
    e[s].pb(edge(t,d,v));
    e[t].pb(edge(s,d,v));
  }
  pd(solve());
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 5136
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;

const void chmax(double &a, double b)
{
  a = max(a, b);
}


struct edge
{
  int to, cost, v;
};

int main()
{
  int N, M, P;
  vector< edge > g[200];

  cin >> N >> M >> P;
  for(int i = 0; i < M; i++) {
    int s, t, d, v;
    cin >> s >> t >> d >> v;
    --s, --t;
    g[s].emplace_back((edge) {t, d, v});
    g[t].emplace_back((edge) {s, d, v});
  }

  double dp[1001][200];
  fill_n(*dp, 1001 * 200, -1);
  dp[0][0] = 0;
  for(int i = 0; i < P; i++) {
    for(int j = 0; j < N; j++) {
      if(dp[i][j] < 0) continue;
      for(auto &e : g[j]) {
        chmax(dp[i + 1][j], dp[i][j] + (double) e.v / e.cost);
        if(i + e.cost <= P)
          chmax(dp[i + e.cost][e.to], dp[i][j] + e.v);
      }
    }
  }

  cout << fixed << setprecision(10) << dp[P][0] << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 5320
final_rank: 13