Skip to content

Commit

Permalink
1068
Browse files Browse the repository at this point in the history
  • Loading branch information
JunhwiLee committed May 30, 2024
1 parent 540d78f commit c71befc
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions 이준휘/n1068.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package baekjoon;
import java.util.*;
public class n1068 {
static int[] arr = new int[50];
static boolean[][] vertex = new boolean[50][50];
static boolean[] visited = new boolean[50];
static int result=0;
static void dfs(int n) {
boolean check = false;
//System.out.println(n);
visited[n] = true;
for(int i = 0; i<50; i++) {
if(vertex[n][i] && !visited[i]) {
visited[i] = true;
dfs(i);
check = true;
}
}
if(!check) result++;

}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int top = 0;
for(int i = 0; i<n; i++) {
arr[i] = sc.nextInt();
if(arr[i] == -1) {
top = i;
continue;
}
vertex[arr[i]][i] = true;
vertex[i][arr[i]] = true;
}
int m = sc.nextInt();
if(m == top) {
System.out.println(0);
return;
}
for(int i = 0; i<50; i++) {
vertex[m][i] = false;
vertex[i][m] = false;
}
dfs(top);
System.out.println(result);
}
}

0 comments on commit c71befc

Please sign in to comment.