两条路径AI (CI翻译)
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).
$*m*$ 张神秘纸片,每张纸片上都写着一对整数。众所周知,古人喜欢记录他们经过的道路编号,形式为 «$*a*$ $*b*$» 或 «$*b*$ $*a*$»,其中 $*a*, *b*$ 是由一条道路连接的两个不同城市的编号。考古学家还知道,这些神秘纸片属于两本旅行日志(在那个年代,每次新的旅程都会写一本新的日志)。AI (CI翻译)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*$.
在一次旅程中,旅行者可能多次沿着同一条道路行走,也可能选择不同的方向;在这种情况下,他会在日志中为每次经过道路分别记录一条内容。此外,考古学家认为,旅行者在道路上所选择的方向不会影响记录:形如 «$*a*$ $*b*$» 的记录既可能表示从 $*a*$ 到 $*b*$ 的道路,也可能表示从 $*b*$ 到 $*a*$ 的道路。AI (CI翻译)
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!
考古学家希望将这些纸片按正确顺序排列,并还原出两条旅行路径,但遗憾的是,他们不擅长编程。这正是你需要帮助他们的地方。请帮助他们完成任务!AI (CI翻译)
Input
输入格式
AI (CI翻译)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*$).
第一行包含一个整数 $*m*$($1 ≤ *m* ≤ 10000$)。接下来的 $*m*$ 行中,每行描述一张纸片。每条描述包含两个整数 $*a*, *b*$($1 ≤ *a*, *b* ≤ 10000$,$*a* ≠ *b*$)。AI (CI翻译)
Output
输出格式
AI (CI翻译)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.
第一行输出整数 $*L*_{1}$,表示第一条路径的长度,即描述该路径所需的纸片数量。第二行输出 $*L*_{1}$ 个用空格分隔的整数,表示描述第一条路径的纸片编号。第三行和第四行以同样的方式输出第二条路径的长度 $*L*_{2}$ 以及该路径本身。两条路径都必须至少包含一条道路,即必须满足条件 $*L*_{1} > 0$ 且 $*L*_{2} > 0$。纸片按照其在输入文件中的出现顺序编号为 $1$ 到 $*m*$。输出的编号应按照旅行者经过相应道路的顺序排列。如果答案不唯一,输出任意一种即可。AI (CI翻译)
If it’s impossible to find such two paths, output «-1».
如果无法找到这样的两条路径,输出 «-1»。AI (CI翻译)
Don’t forget that each paper should be used exactly once, i.e $*L*_{1} + *L*_{2} = *m*$.
不要忘记每张纸片都必须恰好使用一次,即 $*L*_{1} + *L*_{2} = *m*$。
AI (CI翻译)
样例
2
4 5
4 3
1
2
1
1
1
1 2
-1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。