Connectivity

아직 제출이 없습니다시간 제한8초메모리 제한256 MB

문제

There are nn cities in Byteotia. Nowadays, the country has no highways. However, the Byteotian government planned that in the subsequent years, a network of mm highways will be gradually built. Each of the planned highways will be bidirectional and will be of one of dd types, numbered 11 through dd.

Fix some point of time in the future. We say that an ordered pair of cities (a,b)(a,b) is well-connected if a=ba=b or the following condition holds:  for all types t=1,,dt=1,\ldots,d, one can travel from aa to bb using only highways of type tt.

You are given the order in which the planned highways will be built. Your task is to compute, for all k=1,,mk=1,\ldots,m, the number of pairs of cities that will be well-connected after kk first highways are built.

입력

The first line of the input contains three integers dd, nn, mm (1d2001 \le d \le 200, 1n50001 \le n \le 5000, 1m1,000,0001 \le m \le 1\\,000\\,000), denoting the number of types of highways, the number of cities and the number  of planned highways. The cities are numbered 11 through nn. The following mm lines describe the planned highways. The ii-th of these lines contains three integers a_ia\_i, b_ib\_i, k_ik\_i (1a_i,b_in1 \le a\_i,b\_i \le n, a_ib_ia\_i \neq b\_i, 1k_id1 \le k\_i \le d), denoting that the ii-th highway will run between a_ia\_i and b_ib\_i and will be of type k_ik\_i.

출력

You should output exactly mm lines. The kk-th of these lines should contain a single integer -- the number of (ordered) pairs of cities that are well-connected after the first kk highways are built.