CF1218G.Alpha planetary system

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:128MB

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

Alpha行星系内有三颗行星 XX、YY 和 ZZ,其上居住着一个高度发达的文明。这些行星上的航天港通过星际航天飞机相互连接。航班调度员需为每条已有的航天飞机航线决定往返航班次数:只能选择 11、22 或 33 次。由于Alpha星居民强烈反对对称性,因此存在一条严格规则:任意两个由航天飞机直接连接的航天港,其各自的总航班次数必须不同。

对于每一对彼此连接的航天港,你的任务是为每条航天飞机航线指定一个数字 11、22 或 33,使得任意两个直接相连的航天港,其各自关联的航班总次数互不相同。

你可以假设:

  1. 每颗行星至少拥有一个航天港;
  2. 航天飞机仅在不同行星的航天港之间运行;
  3. 对于任意两个航天港,均存在一系列航天飞机航线,使其可以互相抵达(即整个航天港网络连通);
  4. 任意两个航天港之间至多只有一条航天飞机航线连接。

输入格式

The first row of the input is the integer number NN (3≤N≤100000)(3 \leq N \leq 100 000), representing overall number of spaceports. The second row is the integer number MM (2≤M≤100000)(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.

输入的第一行是整数 NN (3≤N≤100 000)(3 \leq N \leq 100\,000),表示空间港的总数。
第二行是整数 MM (2≤M≤100 000)(2 \leq M \leq 100\,000),表示穿梭机航班连接的数量。

第三行包含 NN 个字符,每个字符均属于集合 {X,Y,Z}\{X, Y, Z\}。第 II 个位置上的字母表示第 II 号空间港所在的行星。例如,字符串 "XYYXZZ" 表示:空间港 00 和 33 位于行星 XX,空间港 11 和 22 位于行星 YY,空间港 44 和 55 位于行星 ZZ。

从第四行开始,每一行包含两个由空格分隔的整数。这两个数均为小于 NN 的自然数,表示相互连通的两个空间港的编号。例如,"12 15" 表示空间港 1212 与空间港 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,2,3}\{1, 2, 3\},表示这两座航天港之间的航天飞机航班次数。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页