#P5332. [JSOI2019] 精准预测

[JSOI2019] 精准预测

Description

Currently, there are nn residents in the Mars town (numbered 1,2,,n1,2,\ldots,n). A machine learning algorithm predicts the life-or-death status of these residents over the next TT moments (numbered 1,2,,T1,2,\ldots,T). Each prediction is one of the following two types:

  • Brothers in Misfortune 00 tt xx yy: At moment tt, if xx is dead, then at moment t+1t+1, yy is dead. (Note that if xx is alive at moment tt, this prediction is also considered correct.)

  • Death God Arrives 11 tt xx yy: At moment tt, if xx is alive, then at moment tt, yy is dead. (Note that if xx is dead at moment tt, this prediction is also considered correct.)

Note that this problem is predicting the life-or-death status at a specific moment. If someone is alive at moment tt and dead at moment t+1t+1, you may assume that some event happened during the time interval from tt to t+1t+1 that caused their death.

Although JYY is very confident in the model obtained from big data statistics, the Martians are shocked by these predictions and feel it is hard to accept such a setting. They even think computer science is a scary cult that has broken their peaceful life. To calm the Martians down, JYY plans to derive some facts from these prediction results that are easier for the Martians to accept.

Specifically, JYY first assumes that all predictions about the Martians' life and death are correct. Based on this, JYY wants to compute, for each resident kk, how many Martians might be able to live together with him until moment T+1T+1. In other words, for each Martian kk, JYY wants to compute

$$\sum_{1 \leq i \leq n,i \neq k} \operatorname{Live}(k,i)$$

where Live(i,j)=1\operatorname{Live}(i,j)=1 means that Martians ii and jj may possibly both be alive at moment T+1T+1; otherwise, Live(i,j)=0\operatorname{Live}(i,j)=0.

Note that Martians cannot be resurrected. A Martian may already be dead at moment 11, and there may also be deaths not covered by any prediction (a Martian can die at any time, but at any moment, a Martian's observed state is either alive or dead). Finally, note that Live\operatorname{Live} is computed independently for each pair of Martians, so Live(x,y)=1\operatorname{Live}(x,y)=1 and Live(y,z)=1\operatorname{Live}(y,z)=1 does not imply Live(x,z)=1\operatorname{Live}(x,z)=1.

Input Format

The first line contains three integers T,n,mT,n,m. The next mm lines each describe a prophecy. The first integer cc of each prophecy indicates its type:

  • c=0c=0: then read t,x,yt,x,y;

  • c=1c=1: then read t,x,yt,x,y.

Output Format

Output nn numbers as the answers, separated by spaces.

3 3 2
0 2 1 3
1 1 2 3
2 1 1

Hint

Translated by ChatGPT 5