Vinjete | 프로그래밍의 벗 PivotOJ
PivotOJ

Vinjete

시간 제한: 3000ms메모리 제한: 512MB출처: CHC 2022 Croatian Olympiad in InformaticsBOJ 25447

문제

After two years of being online, the International Olympiad in Informatics (IOI) is going to be held live. The ISC and ITC are stressed as usual, the competitors are excited, parents proud and nervous, but the person most excited about the event being held on-site is Mr. Malnar. Once more he will taste the early-morning grape juice at the Zagreb airport, once more he will taste the finest Asian recipes, once more he will enjoy the daily excursions.

More experienced among you will ask themselves: “What excursions?! Mr. Malnar almost never takes the organized excursions with the rest of the delegations.”. You’re right, he doesn’t, he plans his own excursions months ahead of the event.

First he solves all the car rental logistics, then he makes a short list of NN cities he’d like to visit. He circles these cities on the map and connects each pair of cities that are directly connected via a highway. Interestingly, this year he drew exactly (N1)(N - 1) connections, and realized there exists a path between each pair of cities using these highways.

That’s not all, it looks like there are MM different types of vignettes that you’re able to purchase in Asia. For each highway, it is known what subset of vignette types you need to have. Mr. Malnar immediately indexed all the different vignette types using integers from 11 to MM. Interestingly, he managed to index them in such a way that in order to travel via ii-th highway, you need buy all vignettes with indices greater or equal lil_i and smaller or equal rir_i.

Similarly, he indexed all the cities with integers from 11 to NN such that Yogyakarta, a city in Indonesia hosting the olympiad, is denoted with 11.

To better plan his routes, he decided to ask you to write a program that will compute, for each city, what is the smallest number of vignettes he has to purchase in order to travel from Yogykarta to that city.

입력

The first line contains integers NN and MM from the task description.

The ii-th of the next N1N - 1 lines contains aia_i, bib_i, lil_i and rir_i meaning that the ii-th highway connects cities with indices aia_i and bib_i (1 ≤ a_i , b_i ≤ N, a_i ≠ b_i), and that travelling via that highway entails buying vignettes with indices from an interval [li,ri][l_i , r_i ] (1 ≤ l_i ≤ r_i ≤ M).

The highways are such that they connect each pair of the NN cities.

출력

The ii-th of the N1N - 1 lines should contain the smallest number of vignettes Mr. Malnar has to buy in order to travel from Yogykarta (city with index 11) to city with index (i+1)(i + 1).

예제

예제 1

입력
6 6
1 2 2 4
1 3 1 4
2 4 3 5
2 5 5 6
3 6 2 3
출력
3
4
4
5
4

예제 2

입력
5 6
1 2 2 2
2 3 3 3
3 5 1 5
3 4 1 1
출력
1
2
3
5
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.