OI Problems   关于

#k0q0w0. Two Paths

时间限制:2 s       空间限制:62.5 MiB       标签: 图论 欧拉路 CodeForces 

算法难度等级:5       思维难度等级:6       实现难度等级:5


本题来源于:Codeforces Beta Round 36 Problem E

题目大意

给定一个有 mm 条无向边,至多有 10410^4 个点,可能有重边,不保证联通的图,请在这个图上找出两条路径,使得这两条路径覆盖了图中每一条边仅一次。

1m1041\leq m\leq 10^4

题目描述

Once archaeologists found mm 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 ba\ b » or « b ab\ a », where a, ba,\ 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 ba\ b » could refer to the road from aa to bb as well as to the road from bb to aa.

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!

输入格式

The first input line contains integer mm (1m1041\leq m\leq 10^4). Each of the following mm lines describes one paper. Each description consists of two integers a, ba,\ b (1a, b1041\leq a,\ b\leq 10^4, a\not=b).

输出格式

In the first line output the number L1L_1. That is the length of the first path, i.e. the amount of papers in its description. In the following line output L1L_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 L2L_2 and the path itself. Both paths must contain at least one road, i.e. condition L1>0L_1 > 0 and L2>0L_2 > 0 must be met. The papers are numbered from 11 to mm 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 L1+L2=mL_1+L_2=m.

样例输入输出

2
4 5
4 3
1
2 
1
1
1
1 2
-1