Submission #403146

#TimeUsernameProblemLanguageResultExecution timeMemory
403146rainliofficialCarnival (CEOI14_carnival)Java
0 / 100
115 ms9504 KiB
import java.io.*; import java.util.*; public class carnival { static int n; public static void main(String[] args) throws IOException{ BufferedReader file = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(file.readLine()); ArrayList<Integer>[] arr = new ArrayList[n]; for (int i=0; i<n; i++){ arr[i] = new ArrayList<>(); } for (int i=0; i<n; i++){ for (int j=i+1; j<n; j++){ if (get(new int[] {i+1, j+1}) == 1){ arr[i].add(j); arr[j].add(i); } } } int[] used = new int[n]; int group = 1; for (int i=0; i<n; i++){ if (used[i] == 0){ dfs(i, used, arr, group); group++; } } System.out.print("0"); for (int i : used){ System.out.print(" " + i); } } public static void dfs(int curr, int[] used, ArrayList<Integer>[] arr, int group){ used[curr] = group; for (int i : arr[curr]){ if (used[i] == 0){ dfs(i, used, arr, group); } } } public static int get(int[] arr) throws IOException{ System.out.print(arr.length); for (int i=0; i<arr.length; i++){ System.out.print(" " + arr[i]); } System.out.flush(); BufferedReader file = new BufferedReader(new InputStreamReader(System.in)); return Integer.parseInt(file.readLine()); } }

Compilation message (stderr)

Note: carnival.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...