CF730C.Bulmart

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The first line contains two integers nn , mm (1<=n<=5000(1<=n<=5000 , 0<=m<=min(5000,n(n1)/2))0<=m<=min(5000,n·(n-1)/2)) . Each of the next mm lines contains two integers xex_{e} and yey_{e} , meaning that the ee -th road connects cities xex_{e} and yey_{e} ( 1<=xe,ye<=n1<=x_{e},y_{e}<=n ).

The next line contains a single integer ww ( 1<=w<=50001<=w<=5000 ) — the total number of Bulmart stores in Berland. Each of the next ww lines contains three integers describing the ii -th store: ci,ki,pic_{i},k_{i},p_{i} ( 1<=ci<=n,1<=ki,pi<=21051<=c_{i}<=n,1<=k_{i},p_{i}<=2·10^{5} ).

The next line contains a single integer qq ( 1<=q<=10001<=q<=1000 ) — the number of queries. Each of the next qq lines contains three integers describing the jj -th query: gj,rjg_{j},r_{j} and aja_{j} ( 1<=gj<=n1<=g_{j}<=n , 1<=rj,aj<=1091<=r_{j},a_{j}<=10^{9} )

输入格式

Output qq lines. On the jj -th line, print an answer for the jj -th query — the minimum amount of time needed to deliver rjr_{j} shovels to the customer in city gjg_{j} spending no more than aja_{j} burles. Print -1 if there is no solution for the jj -th query.

输出格式

输入输出样例

  • 输入#1

    6 4
    4 2
    5 4
    1 2
    3 2
    2
    4 1 2
    3 2 3
    6
    1 2 6
    2 3 7
    3 1 2
    4 3 8
    5 2 5
    6 1 10
    

    输出#1

    2
    -1
    2
    2
    3
    -1
    
首页