-
[백준] 10159 저울ALGORITHM/BOJ 2021. 8. 31. 23:38
https://www.acmicpc.net/problem/10159
2021-08-31
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main {static int N, M;static int[][] dist;public static void main(String[] args) throws Exception{BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer(bf.readLine().trim());N = Integer.parseInt(st.nextToken());st = new StringTokenizer(bf.readLine().trim());M = Integer.parseInt(st.nextToken());dist = new int[N][N];for(int i = 0; i < N; i++) {for(int j = 0; j < N; j++) {if(i == j) continue;dist[i][j] = 987654321;}}for(int i = 0; i < M; i++) {st = new StringTokenizer(bf.readLine());int a = Integer.parseInt(st.nextToken()) - 1;int b = Integer.parseInt(st.nextToken()) - 1;dist[a][b] = 1;}for(int mid = 0; mid < N; mid++) {for(int start = 0; start < N; start++) {for(int end = 0; end < N; end++) {if(dist[start][end] > dist[start][mid] + dist[mid][end]) {dist[start][end] = dist[start][mid] + dist[mid][end];}}}}int[] ans = new int[N];for(int i = 0; i < N; i++) {for(int j = 0; j < N; j++) {if(i == j) continue;if(dist[i][j] == 987654321 && dist[j][i] == 987654321) ans[i]++;}}for(int i = 0; i < N; i++) {System.out.println(ans[i]);}}}cs #문제풀이
https://void2017.tistory.com/317?category=820802
어제 푼 이 문제 때문에 풀었다. 완전 똑같은 문제더라..
'ALGORITHM > BOJ' 카테고리의 다른 글
[백준] 2470 두 용액 (0) 2021.09.26 [백준] 2075 N번째 큰 수 (0) 2021.09.26 [백준] 1717 집합의 표현 (0) 2021.08.14 [백준] 1074 Z (0) 2021.07.13 [백준] 2630 색종이 만들기 (0) 2021.07.09