마을들이 일렬로 놓인 나라에서 케이블을 추가하거나 제거하는 날이 지날 때마다, 특정 지점의 붕괴로 그 지점을 가로지르는 케이블이 모두 끊긴 뒤 모든 마을이 기지국에 도달하도록 설치할 기지국의 최소 개수를 구한다.
어려움8그래프유니온 파인드분할 정복동적 계획법아직 제출이 없습니다시간 제한6초메모리 제한512 MBThere are N towns along a deep linear valley in JOI Country. Towns are numbered 0, 1, . . . , N −1 in order of distance from the sea.
Mr. I, the chair of JOI Country Scientific Committee, is going to maintain bidirectional communication cables between the towns. Currently there are no cables in JOI Country.
Mr. I has a cable construction plan for C days. The plan on the (i + 1)-th day (0 ≤ i ≤ C − 1) is represented by three integers Ti, Xi, Yi, which mean:
Cliff collapse often happens in JOI Country. If collapse happens between town x and town x + 1 (0 ≤ x ≤ N − 2), any cable which connects a town numbered at most x and a town numbered at least x + 1 becomes unavailable. In JOI Country, when collapse happens, they choose some towns to install base stations. Base stations should be installed in such a way that, from any town, it is possible to reach a base station by following available cables.
Mr. I is concerned with the number of towns to install base stations when collapse happens during the construction period. He has Q questions: the (j + 1)-th question is represented by two integers Wj, Pj, which mean that he wants to know the minimum number of base stations which should be installed if collapse happens between town Pj and town Pj + 1 at the end of the (Wj + 1)-th day.
You, as an assistant of Mr. I, are in charge of writing a program to answer Mr. I’s questions.
Consider the case where there are 5 towns. In the following, (x, y) denotes a cable connecting town x and town y.