#364
Unrated
MooTube
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

In his spare time, Farmer John has created a new video-sharing service, which he names MooTube. On MooTube, Farmer John's cows can record, share, and discover many amusing videos. His cows already have posted NN videos (1N100,0001 \leq N \leq 100,000), conveniently numbered 1N1 \ldots N. However, FJ can't quite figure out how to help his cows find new videos they might like.

FJ wants to create a list of "suggested videos" for every MooTube video. This way, cows will be recommended the videos most relevant to the ones they already watch.

FJ devises a metric of "relevance," which determines, as the name suggests, how relevant two videos are to each other. He picks N1N-1 pairs of videos and manually computes their pairwise relevance. Then, FJ visualizes his videos as a network, where each video is a node and the N1N-1 pairs of videos he manually considered are connected. Conveniently, FJ has picked his N1N-1 pairs so that any video can be reached from any other video along a path of connections in exactly one way. FJ decides that the relevance of any pair of videos should be defined as the minimum relevance of any connection along this path.

Farmer John wants to pick a value KK so that next to any given MooTube video, all other videos with relevance at least KK to that video will be suggested. However, FJ is worried that too many videos will be suggested to his cows, which could distract them from milk production! Therefore, he wants to carefully set an appropriate value of KK. Farmer John would like your help answering a number of questions about the suggested videos for certain values of KK.

입력

The first line of input contains NN and QQ (1Q100,0001 \leq Q \leq 100,000).

The next N1N-1 lines each describe a pair of videos FJ manually compares. Each line includes three integers pip_i, qiq_i, and rir_i (1pi,qiN,1ri1,000,000,0001 \leq p_i, q_i \leq N, 1 \leq r_i \leq 1,000,000,000), indicating that videos pip_i and qiq_i are connected with relevance rir_i.

The next QQ lines describe Farmer John's QQ questions. Each line contains two integers, kik_i and viv_i (1ki1,000,000,000,1viN1 \leq k_i \leq 1,000,000,000, 1 \leq v_i \leq N), indicating that FJ's iith question asks how many videos will be suggested to viewers of video viv_i if K=kiK = k_i.

출력

Output QQ lines. On line ii, output the answer to FJ's iith question.

예제 입력 1

4 3
1 2 3
2 3 2
2 4 4
1 2
4 1
3 1

예제 출력 1

3
0
2
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.