CF27D.Ring Road 2

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve which lies inside or outside the ring. New roads will have no common points with the ring (except the endpoints of the road).

Now the designers of the constructing plan wonder if it is possible to build the roads in such a way that no two roads intersect (note that the roads may intersect at their endpoints). If it is possible to do, which roads should be inside the ring, and which should be outside?

众所周知,Berland 有 nn 座城市,它们构成了“银环”——城市 ii 与城市 i+1i+1(其中 1≤i<n1 \le i < n)之间由一条道路相连,同时城市 nn 与城市 11 之间也由一条道路相连。政府决定修建 mm 条新道路。待建道路的清单已经拟定,每条新道路将连接两座城市。每条新道路应为一条曲线,且完全位于环的内部或外部。新道路除端点外,不得与环有任何公共点。

现在,建设方案的设计者想知道:是否可能以某种方式修建这些道路,使得任意两条道路互不相交(注意:道路可在端点处相交)?若可行,哪些道路应建在环内,哪些应建在环外?

输入格式

The first line contains two integers n and m (4 ≤ n ≤ 100, 1 ≤ m ≤ 100). Each of the following m lines contains two integers a__i and b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i). No two cities will be connected by more than one road in the list. The list will not contain the roads which exist in the Silver ring.

第一行包含两个整数 nn 和 mm(4≤n≤1004 \leq n \leq 100,1≤m≤1001 \leq m \leq 100)。接下来的 mm 行每行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,且 ai≠bia_i \neq b_i)。列表中任意两个城市之间至多由一条道路连接。该列表不包含银环(Silver ring)中已存在的道路。

输出格式

If it is impossible to build the roads in such a way that no two roads intersect, output Impossible. Otherwise print m characters. i-th character should be i, if the road should be inside the ring, and o if the road should be outside the ring. If there are several solutions, output any of them.

如果无法以任意两条道路都不相交的方式修建这些道路,则输出 Impossible。否则,输出一个长度为 mm 的字符串;其中第 ii 个字符应为 i(表示第 ii 条道路应建在环内),或 o(表示第 ii 条道路应建在环外)。若存在多种可行方案,输出任意一种即可。

输入输出样例

  • 输入#1

    4 2
    1 3
    2 4

    输出#1

    io
  • 输入#2

    6 3
    1 3
    3 5
    5 1

    输出#2

    ooo

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

首页