CF36E.Two Paths

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:64MB

AC君温馨提醒

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

题目描述

Once archaeologists found m mysterious papers, each of which had a pair of integers written on them. Ancient people were known to like writing down the indexes of the roads they walked along, as «a b» or «b a», where a, b are the indexes of two different cities joint by the road . It is also known that the mysterious papers are pages of two travel journals (those days a new journal was written for every new journey).

During one journey the traveler could walk along one and the same road several times in one or several directions but in that case he wrote a new entry for each time in his journal. Besides, the archaeologists think that the direction the traveler took on a road had no effect upon the entry: the entry that looks like «a b» could refer to the road from a to b as well as to the road from b to a.

The archaeologists want to put the pages in the right order and reconstruct the two travel paths but unfortunately, they are bad at programming. That’s where you come in. Go help them!

考古学家曾发现 mm 张神秘纸页,每张纸上都写有一对整数。古人习惯将自己所走道路的编号记录下来,形式为 «aa bb» 或 «bb aa»,其中 aa、bb 是由该道路连接的两个不同城市的编号。此外,已知这些神秘纸页分别来自两本旅行日志(当时每次新旅程都会启用一本新日志)。

在一次旅程中,旅行者可能多次沿同一条道路往返行走;每当如此,他都会在日志中新增一条记录。此外,考古学家认为:旅行者在道路上行进的方向对记录内容并无影响——即形如 «aa bb» 的记录,既可表示从城市 aa 到城市 bb 的道路,也可表示从城市 bb 到城市 aa 的道路。

考古学家希望将这些纸页按正确顺序排列,并复原出这两条旅行路径。但不幸的是,他们不擅长编程。此时,就轮到你来帮忙了!

输入格式

The first input line contains integer m (1 ≤ m ≤ 10000). Each of the following m lines describes one paper. Each description consists of two integers a, b (1 ≤ a, b ≤ 10000, a ≠ b).

第一行输入包含整数 mm(1≤m≤100001 \leq m \leq 10000)。接下来的 mm 行每行描述一篇论文。每篇论文的描述由两个整数 aa、bb(1≤a,b≤100001 \leq a, b \leq 10000,且 a≠ba \neq b)组成。

输出格式

In the first line output the number _L_1. That is the length of the first path, i.e. the amount of papers in its description. In the following line output _L_1 space-separated numbers — the indexes of the papers that describe the first path. In the third and fourth lines output similarly the length of the second path _L_2 and the path itself. Both paths must contain at least one road, i.e. condition _L_1 > 0 and _L_2 > 0 must be met. The papers are numbered from 1 to m according to the order of their appearance in the input file. The numbers should be output in the order in which the traveler passed the corresponding roads. If the answer is not unique, output any.

If it’s impossible to find such two paths, output «-1».

Don’t forget that each paper should be used exactly once, i.e _L_1 + _L_2 = m.

第一行输出数字 L1L_1,即第一条路径的长度(也就是该路径描述中所含论文的数量)。
接下来一行输出 L1L_1 个用空格分隔的数字——即描述第一条路径的各篇论文的编号。
第三行和第四行以同样方式分别输出第二条路径的长度 L2L_2 及其本身。
两条路径均必须至少包含一条道路,即需满足 L1>0L_1 > 0 且 L2>0L_2 > 0。
论文按其在输入文件中出现的顺序编号为 11 至 mm。
输出的编号顺序应与旅行者经过对应道路的顺序一致。
若答案不唯一,输出任意一组解即可。

若无法找到满足条件的两条路径,则输出 −1。

请注意:每篇论文必须恰好使用一次,即需满足 L1+L2=mL_1 + L_2 = m。

输入输出样例

  • 输入#1

    2
    4 5
    4 3

    输出#1

    1
    2 
    1
    1
  • 输入#2

    1
    1 2

    输出#2

    -1

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

首页