[java] import java.util.*; import java.util.Map.Entry; import java.math.*; public class Main{ static int group[] = new int [205]; static Vector <Vector> adj = new Vector <Vector> (); public static int divide(int p){ group[p+1] = -2; for (int j = 0; j < adj.get(p).size(); j ++){ int v = (int) adj.get(p).get(j); if (group[v] == -1){ return (group[p+1] = 1 - divide(v-1)); } if (group[v] > -1){ return (group[p+1] = 1 - group[v]); } } if (group[p+1] == -2) return (group[p+1] = 0); return 0; } public static void main(String args[]){ Scanner cin = new Scanner(System.in); int n = cin.nextInt(); for (int i = 1; i <= n; i ++){ int tmp = 0; Vector <Integer> tmpv = new Vector <Integer> (); while((tmp = cin.nextInt()) != 0){ tmpv.addElement(tmp); } adj.addElement(tmpv); } boolean ok = true; for (int i = 0; i < adj.size(); i ++){ group[i+1] = -1; if (adj.get(i).size() == 0){ ok = false; break; } } for (int i = 0; i < adj.size(); i ++){ group[i+1] = divide(i); } if (ok == false){ System.out.println("0"); } else{ Vector <Integer> ans = new Vector <Integer> (); for (int i = 1; i <= n; i ++){ if (group[i] == 0){ ans.addElement(i); } } System.out.println(ans.size()); for (int i = 0; i < ans.size(); i ++){ if (i > 0) System.out.print(" "); System.out.print(ans.get(i)); } System.out.println(""); } cin.close(); } } [/java]