#P2913. Thresher Pulley Rotation

    ID: 16171 Type: Default 1000ms 256MiB

Thresher Pulley Rotation

Thresher Pulley Rotation

Farmer John has an old-time thresher (wheat harvester) that requires belts to be installed on various gears (pulleys) to operate. The engine drives pulley 1 in a clockwise direction. Pulleys are connected by belts in one of two configurations: a straight belt connection, which causes the driven pulley to rotate in the same direction as the driving pulley, or a crossed belt connection, which causes the driven pulley to rotate in the opposite direction.

There are N pulleys (with 2 \(\leq N \leq 1000\)) and N-1 belts. Each belt is described by three integers:

  • \(S_i\) - the driving (source) pulley,
  • \(D_i\) - the driven (destination) pulley,
  • \(C_i\) - the connection type, where 0 denotes a straight connection and 1 denotes a crossed connection.

Note: The belts are listed in a random order. Given that pulley 1 is driven clockwise by the engine, determine the drive direction of pulley N.

Hint: You can view the effect of each belt as flipping the rotation if the belt is crossed. Initialize pulley 1 as clockwise, and then propagate the rotation through the network of pulleys.

inputFormat

The first line contains the integer \(N\) representing the number of pulleys. Each of the next \(N-1\) lines contains three integers \(S_i\), \(D_i\), and \(C_i\) (with \(C_i = 0\) for a straight belt and \(C_i = 1\) for a crossed belt), separated by spaces. The order of the belts is arbitrary.

outputFormat

Output a single line containing either clockwise or counterclockwise indicating the rotation direction of pulley \(N\).

sample

4
1 2 0
2 3 0
3 4 1
counterclockwise