Asphalting of Road

January 16, 2021
Asphalting of road
1 2nd

memory restriction per test

256 megabytes

City X consists of vertical and horizontal limitless roads, forming  ×  intersections. Roads (both vertical and horizontal) are numbered from 1 to , and intersections tend to be indicated because of the amounts of the roads that form them.

Sand roadways have traditionally already been recognized outdated, therefore the decision had been meant to asphalt them. To work on this, a team of workers ended up being employed and a schedule of work was made, according to that your intersections must certanly be asphalted.

Path repairs are planned for 2 times. On the -th day's the team arrives at the -th intersection when you look at the listing of course none for the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team makes the intersection, without performing anything with the roads.

According to the routine of road works tell for which times at least one road should be asphalted.


Initial line includes integer (1 ≤  ≤ 50) — the amount of vertical and horizontal roads into the city.

After that 2 outlines support the order of intersections when you look at the schedule. The -th of them contains two numbers ,   (1 ≤ ,   ≤ ), separated by an area, and and therefore the intersection that goes -th in the schedule reaches the intersection of the -th horizontal and -th vertical roadways. It's assured that most the intersections inside schedule are distinct.


In single line print the amounts of the occasions whenever road works are happening in ascending order. The days are numbered starting from 1.


Within the test the brigade acts like that:

  1. Regarding first day the brigade concerns the intersection of the 1-st horizontal therefore the 1-st vertical roadway. As not one of them is asphalted, the employees asphalt the 1-st straight as well as the 1-st horizontal road;
  2. On the second time the brigade regarding the workers concerns the intersection associated with 1-st horizontal together with 2-nd vertical road. The 2-nd vertical road wasn't asphalted, but given that 1-st horizontal road has been asphalted regarding first day, the workers leave and do not asphalt everything;
  3. Regarding 3rd day the brigade of the employees come to the intersection of 2-nd horizontal in addition to 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but whilst the 1-st straight roadway is asphalted from the first-day, the workers leave and never asphalt something;
  4. In the 4th time the brigade come to the intersection created because of the intersection associated with the 2-nd horizontal and 2-nd straight roadway. As not one of them was asphalted, the workers asphalt the 2-nd vertical plus the 2-nd horizontal roadway.
Share this Post