|
@@ -0,0 +1,35 @@
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+public class main3 {
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ //数据录入
|
|
|
|
+ Scanner scanner = new Scanner(System.in);
|
|
|
|
+ int len = Integer.parseInt(scanner.nextLine());
|
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
|
+ while (true) {
|
|
|
|
+ String s = scanner.nextLine();
|
|
|
|
+ if (s.trim().length() == 0) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ list.add(s);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("yes");
|
|
|
|
+ HashSet<Integer> integers = new HashSet<>();
|
|
|
|
+ integers.add(0);
|
|
|
|
+ dfs(0, list, integers);
|
|
|
|
+ System.out.println(integers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void dfs(Integer num, ArrayList<String> list, HashSet<Integer> integers) {
|
|
|
|
+ int nextNum = 0;
|
|
|
|
+ if (integers.contains(num)) {
|
|
|
|
+ String[] s1 = list.get(0).split(" ");
|
|
|
|
+ if (integers.contains(Integer.parseInt(s1[0]))) {
|
|
|
|
+ nextNum = Integer.parseInt(s1[0]);
|
|
|
|
+ integers.add(nextNum);
|
|
|
|
+ }
|
|
|
|
+ dfs(nextNum, list, integers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|