Kingdom Division | 프로그래밍의 벗 PivotOJ
PivotOJ

Kingdom Division

시간 제한: 2000ms메모리 제한: 1024MB출처: Programmeringsolympiaden 2016 — katt2BOJ 21349

문제

In a far away kingdom, there are NN cities numbered between 00 and N1N - 1. The cities are connected by N1N - 1 two-way roads. Each road connects exactly two cities, such that there is a unique path between any pair of cities. Each city ii has some value C[i]C[i] (possibly negative).

Unfortunately, the old king of the kingdom died, without appointing a successor. Thus a civil war broke out in the kingdom, between the PP lords (also numbered between 00 and P1P - 1) who wish to gain control of the kongdom.

After a long and terrible war, the lords realized none of them could beat all the other lords in the war. They agreed to a truce, and decided to divide the kingdom into PP parts, one part per lord. The parts must be so that if two cities aa and bb lie in the same part, all cities in the unique path between them must also lie in that part. Since no lord wants to be left out, each one must be given at least one city.

Since no lord wants to get less than another, the value of each part must be the same. The value of a part is the sum of the values of all cities in that part.

입력

The sample judge reads input in the following format:

  • line 11: N P
  • line 22: C[0] C[1] .. C[N - 1]
  • line 33: F[0] F[1] .. F[N - 2]
  • line 44: T[0] T[1] .. T[N - 2]

출력

The sample judge will first write a single line with the return value of division(N, P, C, F, T). The next line will contain NN integers containing the input to the parts(R) call.

예제

예제 1

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