이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.*;
import java.util.*;
public class luk {
static int N;
static ArrayList<Integer>[] adj;
public static void main(String[] args) throws IOException, FileNotFoundException {
Scanner in = new Scanner(System.in);
// Scanner in = new Scanner(new File("luk.in"));
// PrintWriter out = new PrintWriter("luk.out");
N = in.nextInt();
adj = new ArrayList[N];
for(int i = 0; i < N; i++){
adj[i] = new ArrayList<>();
}
for(int i = 0; i < N - 1; i++){
int a = in.nextInt() - 1;
int b = in.nextInt() - 1;
adj[a].add(b);
adj[b].add(a);
}
int a = 1;
int b = N;
while(a != b){
int mid = (a + b)/2;
if(recurse(0, -1, mid) <= 0){
b = mid;
} else {
a = mid + 1;
}
}
System.out.println(a);
}
static int recurse(int position, int prev, int crew){
int j = 0;
for(int ap: adj[position]){
if(ap != prev){
j += recurse(ap, position, crew) + 1;
}
}
return Math.max(0, j - crew);
}
}
컴파일 시 표준 에러 (stderr) 메시지
Note: luk.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
# | 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... |
# | 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... |