This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.*;
import java.io.*;
public class carnival {
private static ArrayList<Integer> components;
private static HashMap<Integer, ArrayList<Integer>> sets;
public static void main(String[] args) throws IOException {
new carnival();
}
public carnival() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
sets = new HashMap<>();
components = new ArrayList<>();
components.add(1);
sets.put(1, new ArrayList<>());
sets.get(1).add(1);
for(int i = 2; i <= n; i++){
boolean added = false;
for(Integer val: components){
System.out.println("2 " + i + " " + val);
st = new StringTokenizer(br.readLine());
if ((Integer.parseInt(st.nextToken()) == 1)){
sets.get(val).add(i);
added=true;
break;
}
}
if (!added){
sets.put(i, new ArrayList<>());
sets.get(i).add(i);
components.add(i);
}
}
int[] result = new int[n+1];
int m = 1;
for(Integer i: components){
for(Integer j: sets.get(i)){
result[j] = m;
} m++;
}
for(int i: result){
System.out.print(i + " ");
}
System.out.println();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |