英语题目作业(11)

原题:

Travel Expense

 1000ms  65536K

描述:

Huanhuan is always working on fansy programming questions. However, today he decided to give himself a break and travel to a beautiful country. Therefore, another problem arose.

There are totally nn cities in the country. There are mm two-way roads, each of them directly connects two different cities. As the country has a solid transportation system, there is always a path connects every two cities.

Huanhuan arrives at city S and wants to carry as many items as possible to city TT. Everyday he will go through exactly one road. For every road he pass, a fee is to pay. Due to the policy, the fee depends on number of items you carry and the number of days you enter the country. More exactly, the fee for each road is kdkd, where kk is the number of the items Huanghuan is to carry and dd is the number of days he enter the country.

For example, Huanghuan arrives ar city 11, and aim to city 33. The path he chooses is 1−>2−>31−>2−>3 carrying 22 items. Then the fee of road 1−>21−>2 will be 2121 and the fee of road 2−>32−>3 will be 2222. So the total expense is 21+22=621+22=6

Now, you are tasked to help him to decide the maximum number of items he can carry since he only have limited budget.

However, Huanhuan is prepared to travel multiple times in the future. There will be totally QQ query for you.

输入:

The first line contains two interger n,m(1≤n≤100,m≤n(n+1)2)n,m(1≤n≤100,m≤n(n+1)2), where nn is number of cities and mm is the number of road. (It's guaranteed that every two cities are connected, and there are no two roads directly connects the same two cities.)

Then, mm lines follow, the ithith lines contains two integer ui,vi(1≤ui,vi≤n,ui≠vi)ui,vi(1≤ui,vi≤n,ui≠vi), denoting the ithith roads connects city uiui and vivi.

The next lines contains one integer Q(1≤Q≤105)Q(1≤Q≤105), denoting the number of query.

Then follows QQ lines, each line contains 33 integers S,T,B(1≤S,T≤n,0≤B≤109)S,T,B(1≤S,T≤n,0≤B≤109), denoting the city arrived, the city aimed and the budget.

输出:

For each query, print one integer as the maximum item Huanhuan can carry from city SS to TT.

样例输入:

3 2
1 2
2 3
3
1 2 5
1 3 5
2 3 2

样例输出:

5
1
2

翻译:

旅游消费

Huanhuan总是在解决编程问题。然而,今天他决定给自己放个假,去一个漂亮的国家旅游。因此,另一个问题出现了。

这个国家一共有n个城市。有m条道路分别直接连通两个城市。因为这个国家有一个坚固的交通系统,总有一条路连通两个城市。

Huanhuan到了城市S,想尽可能多的找到通往城市T的路。他决定每天走一条路。对于他走过的每条路,都要付过路费。因为政策,费用依据走过道路的数量和到达该国家的天数决定。更确切地说,过每条路的费用是k^d,k是Huanhuan走过的路的数目,d是他进入该国家的天数。

例如,Huanhuan到达城市1,目的地是城市3.他选择的道路是1->2->3,经过两条路。道路1->2要收费2^1,道路2->3将收费2^2,。所以总共花费2^1+2^2=6.

现在,你的任务是帮助他算出在他花完预算之前他最多能走几条路。

然而,Huanhuan准备将来多旅游几次。他将总共问你Q次。

输入:

第一行包括2个整数n,m(1<=n<=100,m<=n*(n+1)/2),n是城市数目,m是道路的数量。(每两个城市与两个城市相连,没有两条路直接与相同的两个城市相连)

接下来m行,第i行包含ui,vi(1<=ui,vi<=n,ui!=vi),第i条路连通城市ui和vi。

接下来一行包括一个整数Q(1<=Q<=105),表示问的次数。

接下来Q行,每行包含3个整数S,T,B(1<=S,T<=n,0<=B<=109),分别表示到达的城市,目标城市和预算。

输出:

对于每次询问,输出一个整数表示Huanhuan从S到T最多能走路的条数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值