Bikes vs Cars

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

문제

In Lund, biking is a very common method of transportation. But it is sometimes difficult to fit both cars and cyclists on the narrow streets. To improve the situation, the local governor wants to completely redesign the local street network.

There are NN important locations (numbered from 00 to N1N-1) in Lund that people frequently travel between. People travel between two locations by following a path, which is a sequence of streets going from the first location to the other. A vehicle (car or bike) can travel on a path if all relevant lanes are at least as wide as the vehicle. Each newly built street connects two of these important locations and it has a total width of WW. This width can be arbitrarily partitioned between bike lane and car lane. In Lund, some engineers have recently invented cars and bikes of width 00 (these can travel on lanes with width 00).

The engineers have measured the widths of the cars and bikes in the city. For each pair of important locations, they know the widest car and the widest bike that should be able to travel between them, but the governor also requires that no wider cars or bikes can travel between these two locations.

Formally, you are given for each pair i,ji,j (0i\<jN10 \le i\<j \le N-1) two integer values C_i,jC\_{i,j} and B_i,jB\_{i,j}. Your task is to construct a network of streets connecting the NN locations. The streets all have a width of WW, but for each street ss you can decide the width of its bike lane b_sb\_s and this determines the width of its car lane Wb_sW-b\_s. The network must satisfy the following:

  • It is possible to travel between each pair of locations. Note that this might require a bike or car of width 00.
  • For each pair of locations ii, jj (where i<ji < j), it is possible to travel between ii and jj by only using streets whose car lanes have a width of at least C_i,jC\_{i,j}. Also, C_i,jC\_{i,j} is the maximum number with this property. That is, for all paths between locations ii and jj it holds that at least one of the streets has a car lane of width at most C_i,jC\_{i,j}.
  • For each pair of locations ii, jj (where i<ji < j), it is possible to travel between ii and jj by only using streets whose bike lanes have a width of at least B_i,jB\_{i,j}. Also, B_i,jB\_{i,j} is the maximum number with this property.
  • Can you help the governor of Lund to design such a street network? Because the funding is limited, you can build at most 20232023 streets. You can build multiple streets between the same pair of important locations but you cannot connect a location with itself. All streets can be used in both directions.

입력

The first line of input contains two integer NN and WW, the number of important locations in Lund and the width of the streets that you can build.

The following N1N-1 lines contain the integers C_i,jC\_{i,j}. The jjth of these lines will contain every C_i,jC\_{i,j} where i<ji < j. So the first line will contain only C_0,1C\_{0,1}, the second will contain C_0,2C\_{0,2} and C_1,2C\_{1,2}, the third C_0,3C\_{0,3}, C_1,3C\_{1,3}, C_2,3C\_{2,3}, and so on.

The following N1N-1 lines contain the integers B_i,jB\_{i,j}, on the same format as C_i,jC\_{i,j}.

출력

If it is impossible to construct such a street network, print one line with the string "NO".

Otherwise, print one line with the integer MM, the number of streets of your network.

For each of the following MM lines, print three integers u,v,bu, v, b, indicating that a street with a bike lane of width bb (and a car lane with width WbW-b) goes between uu and vv.

You may use at most 20232023 streets. The streets you output must satisfy 0bW0 \leq b \leq W, 0u,vN10\le u,v \le N-1 and uvu\neq v. You may use multiple streets (possibly of different bike lane width) between the same pair of important locations.

In case there are multiple solutions, you may output any of them.

제한

  • 2N5002 \le N \le 500.
  • 1W1061 \le W \le 10^6.
  • 0C_i,j,B_i,jW0 \le C\_{i,j},B\_{i,j}\le W for all 0i<jN10 \le i < j \le N-1.

힌트

In the first sample, the width of a street is 11 and we need a car lane and a bike lane of width at least 11 between locations 00 and 11. The solution is to have two separate streets connecting the locations, one with a bike lane of width 11 and one with a car lane or width 11.

In the second sample, the width of a street is again 11 and there should be a path with a bike lane of width 11 between every pair of important locations and there is a path between the locations 11 and 22 and 22 and 33 where the width of the car lane is 11 for every street. This contradicts the fact that, as C_1,3=0C\_{1,3}=0, there should not be a path with car lane width 11 from 11 to 33 as we can just join the two aforementioned paths to form such a path. Thus it is not possible to construct such a street network.

In the third sample, the street network below fulfills all the conditions. For example, there should be a path with minimum width of the car lane 1=C_0,51 = C\_{0,5} between location 00 and location 55 (e.g. by following the route 0245)0\to 2\to 4 \to 5), a path where the bike lane has minimum width 3=B_0,53 = B\_{0,5} (e.g. by following the route 0345)0\to 3 \to 4 \to 5). At the same time it can be checked that there are no paths with a wider minimum width for any of the connections. Note that there are many other solutions to the third sample.