每天一翻译之4

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

Travel Expense

描述:

欢欢一直从事于狂热的编程问题,然而,今天他决定休息一天并且去一个很美丽的国家旅行。因此,出现了另一个问题。

这个国家总共有n个城市,有m条两条路的道路,他们中的每一个都是直接连接两条不同的城市。由于这个城市有一套牢固的交通体系,所以每两个城市之间总是连接着一条道路。

欢欢到达了S城,想尽可能把更多的东西带到T城,每一天他都要经过确切的道路,每经过一条道路都需要付费,根据这个政策,费用取决于所携带的物品数量和进入这个国家的天数,更确切地说,每条道路的费用是k^d,其中,k是欢欢想要携带的物品的数量,d是他进入这个国家的天数。

比如,欢欢到达了1城,想要到3城,他选择的路线是1->2->3携带2件物品,因此,这个路1->2的费用是2^1和路2->3的费用是2^2,因此,总共的费用是2^1+2^2=6.

现在,你的任务是帮助他决定他可以携带的物品的最大数量,因为他只有有限的预算。

然而,欢欢准备在未来进行多次的旅行,对你来说将会有Q的查询。

输入:

第一行包括两个整数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<=10^5),表示查询的数量。

接下来的Q行,每一行包括3个整数S,T,B(1<=S,T<=n,0<=B<=10^9),表示到达的城市,目标城市和预算。

输出:

对于每一次查询,输出一个整数作为欢欢可以从S城到T城最大的携带物品。

样例输入:

3 2

1 2

2 3

3

1 2 5

1 3 5

2 3 2

样例输出

5

1

2

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值