惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
Vercel News
Vercel News
D
DataBreaches.Net
Microsoft Azure Blog
Microsoft Azure Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Cloudbric
Cloudbric
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
月光博客
月光博客
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Hugging Face - Blog
Hugging Face - Blog
Security Latest
Security Latest
T
Threatpost
GbyAI
GbyAI
K
Kaspersky official blog
S
SegmentFault 最新的问题
Schneier on Security
Schneier on Security
V
V2EX
W
WeLiveSecurity
Recorded Future
Recorded Future
WordPress大学
WordPress大学
L
LINUX DO - 最新话题
O
OpenAI News
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
有赞技术团队
有赞技术团队
Attack and Defense Labs
Attack and Defense Labs
N
News | PayPal Newsroom
H
Help Net Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Webroot Blog
Webroot Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Troy Hunt's Blog
腾讯CDC
Scott Helme
Scott Helme
P
Privacy & Cybersecurity Law Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
E
Exploit-DB.com RSS Feed

博客园 - zy_nic

SRM 424 div1 900 ProductOfPrices 翻译 .. emacs的c++mode contest contest 我的2-sat模板 Solution to GCJ Practice Contest Problem C, Cycles 约瑟夫问题的数学方法 我的模板 图的应用 pku3411 今天的比赛 关于建图的 死老鼠安装成功 pku3141 hnu 11028 hnu 11015 joj 儿死三八 pku 1273
先帖个题目上来
zy_nic · 2007-09-18 · via 博客园 - zy_nic

Description

Recently wywcgs is interested in stones very much. In the past contest, wywcgs has a stone transportation problem. In that problem, he finds a kind of very beautiful stone which made in city A. wywcgs wants to buy this stone as many as possible. These stones must be transfered to the city B that wywcgs lives along a path from A to B. There will be some roads which doesn't have enough capacity to transfer all the stones, so wywcgs must spend money to widen them. But wywcgs has only a little money, so he wants to make an optimal plan to buy and transfer them.

In that problem, wywcgs transfers these stones only along a single path. But he realized that it's better to transfer them along multiple paths. That is to say, he can divide these stones into some groups and transfer each of them along a different path respectively. Now he wants to design a new plan to buy and transfer them.

Input

Input contains multiple test cases. The first line is a integer T, the number of test cases. Each case begins with three integers N, M, C, P, with 2 <= N <= 1000, 1 <= M <= 10000, 1 <= C <= 100000000, 1 <= P <= 10000, represents the number of city, the number of road, the maximum money wywcgs can spend, the cost of one stone respectively. Next M lines each denotes a road. A road is represented by four numbers u, v, c1, c2, with 0 <= u, v < N, 0 <= c1 <= 10000, 0 <= c2 <= 10000, means this road connects the city u and v, its capacity is c1 and wywcgs must spend c2 money to widen its capacity by one. Cities are numbered from 0 to N-1. City 0 is always A, and city 1 is always B. Roads are all bidirectional, and there may be two or more roads connecting to the same pair of city.

Output

For each test case, output a line contains a integer which means the maximum number of wywcgs can buy.

Sample Input

4
            2 1 1000 1
            0 1 0 2
            2 1 1000 1
            0 1 1 2
            3 1 100000000 1
            0 2 10000 0
            4 4 4 1
            0 2 1 1000
            2 1 1 1000
            0 3 1 0
            3 1 1 1
            

Sample Output

333
            334
            0
            3
            

Hint

Sample 3 : there is no path bwtween 0 and 1, so wywcgs cannot get any stones no matter how much money he has.
Sample 4 : wywcgs can buy 3 stones, 1 stone is transfered along the path 0->2->1 with cost 0, and the other 2 stones are along 0->3->1 with cost 1.