CF1218G.Alpha planetary system

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Three planets XX , YY and ZZ within the Alpha planetary system are inhabited with an advanced civilization. The spaceports of these planets are connected by interplanetary space shuttles. The flight scheduler should decide between 11 , 22 and 33 return flights for every existing space shuttle connection. Since the residents of Alpha are strong opponents of the symmetry, there is a strict rule that any two of the spaceports connected by a shuttle must have a different number of flights.

For every pair of connected spaceports, your goal is to propose a number 11 , 22 or 33 for each shuttle flight, so that for every two connected spaceports the overall number of flights differs.

You may assume that:

1) Every planet has at least one spaceport

2) There exist only shuttle flights between spaceports of different planets

3) For every two spaceports there is a series of shuttle flights enabling traveling between them

4) Spaceports are not connected by more than one shuttle

输入格式

The first row of the input is the integer number NN (3N100000)(3 \leq N \leq 100 000) , representing overall number of spaceports. The second row is the integer number MM (2M100000)(2 \leq M \leq 100 000) representing number of shuttle flight connections.

Third row contains NN characters from the set {X,Y,Z}\{X, Y, Z\} . Letter on IthI^{th} position indicates on which planet is situated spaceport II . For example, "XYYXZZ" indicates that the spaceports 00 and 33 are located at planet XX , spaceports 11 and 22 are located at YY , and spaceports 44 and 55 are at ZZ .

Starting from the fourth row, every row contains two integer numbers separated by a whitespace. These numbers are natural numbers smaller than NN and indicate the numbers of the spaceports that are connected. For example, " 12 1512\ 15 " indicates that there is a shuttle flight between spaceports 1212 and 1515 .

输出格式

The same representation of shuttle flights in separate rows as in the input, but also containing a third number from the set {1,2,3}\{1, 2, 3\} standing for the number of shuttle flights between these spaceports.

输入输出样例

  • 输入#1

    10
    15
    XXXXYYYZZZ
    0 4
    0 5
    0 6
    4 1
    4 8
    1 7
    1 9
    7 2
    7 5
    5 3
    6 2
    6 9
    8 2
    8 3
    9 3
    

    输出#1

    0 4 2
    0 5 2
    0 6 2
    4 1 1
    4 8 1
    1 7 2
    1 9 3
    7 2 2
    7 5 1
    5 3 1
    6 2 1
    6 9 1
    8 2 3
    8 3 1
    9 3 1
    
首页