CF687D.Dividing Kingdom II

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves.

The great kingdom consisted of nn cities numbered from 11 to nn and mm bidirectional roads between these cities, numbered from 11 to mm . The ii -th road had length equal to wiw_{i} . The Great Arya and Pari The Great were discussing about destructing some prefix (all road with numbers less than some xx ) and suffix (all roads with numbers greater than some xx ) of the roads so there will remain only the roads with numbers l,l+1,...,r1l,l+1,...,r-1 and rr .

After that they will divide the great kingdom into two pieces (with each city belonging to exactly one piece) such that the hardness of the division is minimized. The hardness of a division is the maximum length of a road such that its both endpoints are in the same piece of the kingdom. In case there is no such road, the hardness of the division is considered to be equal to 1-1 .

Historians found the map of the great kingdom, and they have qq guesses about the ll and rr chosen by those great rulers. Given these data, for each guess lil_{i} and rir_{i} print the minimum possible hardness of the division of the kingdom.

输入格式

The first line of the input contains three integers nn , mm and qq ( 1<=n,q<=10001<=n,q<=1000 , ) — the number of cities and roads in the great kingdom, and the number of guesses, respectively.

The ii -th line of the following mm lines contains three integers uiu_{i} , viv_{i} and wiw_{i} ( 1<=ui,vi<=n,0<=wi<=1091<=u_{i},v_{i}<=n,0<=w_{i}<=10^{9} ), denoting the road number ii connects cities uiu_{i} and viv_{i} and its length is equal wiw_{i} . It's guaranteed that no road connects the city to itself and no pair of cities is connected by more than one road.

Each of the next qq lines contains a pair of integers lil_{i} and rir_{i} ( 1<=li<=ri<=m1<=l_{i}<=r_{i}<=m ) — a guess from the historians about the remaining roads in the kingdom.

输出格式

For each guess print the minimum possible hardness of the division in described scenario.

输入输出样例

  • 输入#1

    5 6 5
    5 4 86
    5 1 0
    1 3 38
    2 1 33
    2 4 28
    2 3 40
    3 5
    2 6
    1 3
    2 3
    1 6
    

    输出#1

    -1
    33
    -1
    -1
    33
    
首页