Air Traffic Control 3

Time limit: 3sMemory limit: 1024MBInput: Output:

Task

Francesco has just bought the new Flight Simulator game and can't wait to play it. However, given the many flight hours he has already logged in the previous versions of the game, this time he won't play as a pilot but as an air traffic controller.

Francesco’s new workplace.\text{Francesco's new workplace}.

Today Francesco has to coordinate NN airports, between which MM flights will travel. The ii-th flight departs from airport AiA_i at time T1iT1_i and arrives at airport BiB_i at time T2iT2_i: if it departs, it uses the runway of airport AiA_i at time T1iT1_i and the runway of airport BiB_i at time T2iT2_i. A flight that does not depart uses no runway.

Some flights are more important than others, so if one of these does not depart, another specific flight must depart in its place. In particular, there are LL constraints of this kind: if the important flight UjU_j does not depart, flight VjV_j must necessarily depart.

Francesco must also keep in mind the rule, valid for every airport, that if the runway is used (for landing or takeoff) at time tt, it cannot be used in the KK instants before and after. In other words, if a plane takes off or lands on the runway at time tt, no other plane can do so in the time interval [t−K,t+K][t-K,t+K] on the same runway.

Francesco can't manage all of these flights and asks you for help.

If it is possible to choose a subset, possibly even all or none, of the flights to let depart that respects the constraints, print YES and an array of length MM made up of 0 or 1 (0 if the ii-th flight does not depart, 1 if it departs).

If it is not possible to find a subset of flights that respects the constraints, print NO.

You are not required to maximize the number of flights that depart.

Input data

The input file consists of:

  • A line containing the integers NN, MM and KK.
  • MM lines containing the integers AiA_i, T1iT1_i, BiB_i and T2iT2_i for i=0,…,M−1i=0,\ldots,M-1.
  • A line containing the integer LL.
  • LL lines containing the integers UjU_j and VjV_j for j=0,…,L−1j=0,\ldots,L-1.

Output data

The first line of the output file must contain only the string YES or NO.

If the first line contains YES, the second line must contain MM values, each a 0 or a 1, indicating whether each flight departs or not.

Constraints and clarifications

  • 2≤N≤100 0002 \le N \le 100\ 000.
  • 1≤M≤100 0001 \le M \le 100\ 000.
  • 0≤K≤1 000 000 0000 \le K \le 1\ 000\ 000\ 000.
  • 0≤T1i<T2i≤1 000 000 000 000 0000 \le T1_i < T2_i \le 1\ 000\ 000\ 000\ 000\ 000 for each i=0,…,M−1i=0,\ldots,M-1.
  • 0≤Ai,Bi<N0 \le A_i,B_i < N and Ai≠BiA_i \neq B_i for each i=0,…,M−1i=0,\ldots,M-1.
  • At each airport, the departure and arrival times of all the flights are pairwise distinct.
  • 0≤L≤100 0000 \le L \le 100\ 000.
  • 0≤Uj,Vj<M0 \le U_j,V_j < M and Uj≠VjU_j \neq V_j for each j=0,…,L−1j=0,\ldots,L-1.
# Score Constraints
0 0 Examples.
1 15 L=0L=0.
2 20 N,M,L≤20N,M,L \le 20.
3 30 M,K≤2 000M,K \le 2\ 000.
4 35 No additional restrictions.

Example

stdin

3 4 2
0 1 1 10
1 2 2 12
1 20 0 30
2 5 1 11
2
0 1
3 2

stdout

YES
0 1 1 0

Example

stdin

3 3 5
0 10 1 100
1 98 2 200
0 12 2 202
3
0 1
1 2
0 2

stdout

NO

Explanation

In the first sample case Francesco can let flights 11 and 22 depart, which satisfies both constraints. Flights 00 and 33 cannot both depart, because they land at airport 11 at times 1010 and 1111, at most K=2K=2 instants apart.

In the second sample case every two flights use the same runway at most K=5K=5 instants apart (flights 00 and 11 at airport 11, flights 11 and 22 at airport 22, flights 00 and 22 at airport 00), so at most one flight can depart. However, the three constraints require at least two of the three flights to depart. Therefore, the answer is NO.

Log In or Sign Up to be able to send submissions!