문제
The cows are heading back to the barn at the end of a long day, feeling both tired and hungry.
The farm consists of pastures (), conveniently numbered . The cows all want to travel to the barn in pasture . Each of the other pastures contains a cow. Cows can move from pasture to pasture via a set of undirected trails (). The th trail connects a pair of pastures and , and requires time to traverse. Every cow can reach the barn through a sequence of trails.
Being hungry, the cows are interested in potentially stopping for food on their way home. Conveniently, of the pastures contain tasty haybales (), with the th such haybale having a yumminess value of . Each cow is willing to stop at a single haybale along her trip to the barn, but only if the amount of time this adds to her path is at most the yumminess of the haybale she visits. Note that a cow only "officially" visits at most one haybale for dining purposes, although it is fine if her path takes her through other pastures containing haybales; she simply ignores these.
입력
The first line contains three space-separated integers , , and . Each of the next lines contains three integers , , and , describing a trail between pastures and which takes time to traverse ( and are different from each-other, and is a positive integer at most )
The next lines each describe a haybale in terms of two integers: the index of its pasture, and its yumminess value (a positive integer at most ). Multiple haybales can reside in the same pasture.
출력
The output should consist of lines. Line contains the single integer if the cow at pasture can visit and dine on a haybale on the way to the barn, and otherwise.
예제 입력 1
4 5 1
1 4 10
2 1 20
4 2 3
2 3 5
4 3 2
2 7
예제 출력 1
1
1
1
코드를 제출하려면 로그인이 필요합니다.
로그인