publicclassMain{ publicstaticvoidmain(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); HashMap> map = new HashMap<>(); for (int i = 0; i < m; i++) { int l = sc.nextInt(); Set set = new HashSet<>(l); for (int j = 0; j < l; j++) { set.add(sc.nextInt()); } for (Integer integer : set) { Set set1 = map.get(integer); if (set1 == null || set1.isEmpty()) { map.put(integer, set); continue; } set1.addAll(set); map.put(integer, set1); } } Queue queue = new LinkedList<>(); Set result = new HashSet<>(); queue.addAll(map.get(0)); while (!queue.isEmpty()){ Integer i = queue.poll(); Set set = map.get(i); for (Integer j : set) { if (!result.contains(j)){ queue.add(j); result.add(j); } } } System.out.println(result.size()); } }
publicclassMain{ publicstaticvoidmain(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = newint[n]; for (int i = 0; i < a.length; i++) { a[i] = sc.nextInt(); } if (n == 2) { System.out.println(a[0]); } int[] t = Arrays.copyOf(a, n); Arrays.sort(t); int la = t[n / 2 - 1]; int ra = t[n / 2]; for (int i = 0; i < n; i++) { if (a[i] <= la) { System.out.println(ra); } else { System.out.println(la); } } } }