Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Farmer Johns cows are showing off their new dance mooves! At first, all N cows (2N105,2N105) stand in a line with cow ii in the

Farmer Johns cows are showing off their new dance mooves!

At first, all N cows (2N105,2N105) stand in a line with cow ii in the iith position in line. The sequence of dance mooves is given by K (1K21051K2105) pairs of positions (a1,b1),(a2,b2),,(aK,bK)(a1,b1),(a2,b2),,(aK,bK). In each minute i=1Ki=1K of the dance, the cows in positions ai and bi in line swap. The same K swaps happen again in minutes K+12K K+12K, again in minutes 2K+13K2K+13K, and so on, continuing indefinitely in a cyclic fashion. In other words,

  • In minute 1, the cows at positions a1 and b1 swap.
  • In minute 2, the cows at positions a2 and b2 swap.
  • ...
  • In minute K, the cows in positions aK and bK swap.
  • In minute K+1, the cows in positions a1 and b1 swap.
  • In minute K+2 the cows in positions a2 and b2 swap.
  • and so on ...

For each cow, please determine the number of unique positions in the line she will ever occupy.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains integers NN and KK. Each of the next KK lines contains (a1,b1)(aK,bK)(a1,b1)(aK,bK) (1ai

OUTPUT FORMAT (print output to the terminal / stdout):

Print NN lines of output, where the iith line contains the number of unique positions that cow ii reaches.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions