Contaminated Milk#11156

Contaminated Milk

1 секунда
128 мегабајти
Лесно

Farmer John, known far and wide for the high quality of the milk produced on his farm, is hosting a milk-tasting party for of his best friends. Unfortunately, exactly one of the types of milk served at the party has gone bad, but Farmer John does not know which one! Anyone who drinks the bad milk will eventually become sick, either during the remainder of the party or sometime afterward.

You are given a transcript of the party recording who drank which type of milk and at what time, as well as who became sick and when. Based on this information, you can determine which types of milk could possibly be the bad one. Using this information, help Farmer John determine the minimum number of doses of medicine he needs to have on hand to guarantee that he can cure everyone who becomes sick, either during or after the party.

Влез

The first line contains four integers n, m, d, and s~(1 \le n, m \le 50, 1 \le d \le 1000, 1 \le s \le n).

Each of the next lines contains three integers , , and , indicating that person drank milk type at time . The value of is in the range , is in the range , and is in the range . A person may drink the same type of milk several times and may also drink several types of milk at the same point in time.

Each of the next lines contains two integers and , indicating that person becomes sick at time . The value of is in the range , and is in the range . Each person becomes sick at most once, and only because they drank the bad milk at some strictly earlier point in time.

Излез

Print one integer — the minimum number of doses of medicine Farmer John needs to obtain in order to guarantee that he can cure everyone who becomes sick, either during or after the party.

Примери

There are people and types of milk. Person becomes sick at time , while person becomes sick at time . Person does not become sick during the party, although we must consider the possibility that they could become sick later, after the party ends.

Let us consider the milk types one by one to determine which ones could be contaminated. A milk type is potentially bad if every person who became sick drank that milk before becoming sick.

Milk : Both sick people ( and ) drank this type of milk before becoming sick, so milk could be the bad milk. If it is, person also drank it, so a total of people could become sick (with person becoming sick after the party).

Milk : Both sick people drank this type of milk before becoming sick, so milk could also be the bad milk. Nobody else drank this milk, so at most people would need to be cured.

Milk : This cannot be the bad milk because person did not drink it before becoming sick. Person drank milk at time but became sick at time . For milk to have caused person to become sick, they would have had to drink it before time .

Milk : This cannot be the bad milk because person never drank it but nevertheless became sick.

Therefore, Farmer John must obtain doses of medicine, since if milk is bad, all people could eventually become sick.

Пример 1

Loading
Loading