9372번: 상근이의 여행
첫 번째 줄에는 테스트 케이스의 수 T(T ≤ 100)가 주어지고, 각 테스트 케이스마다 다음과 같은 정보가 주어진다. 첫 번째 줄에는 국가의 수 N(2 ≤ N ≤ 1 000)과 비행기의 종류 M(1 ≤ M ≤ 10 000) 가
www.acmicpc.net
이문제는 모든 국가를 여행하는데 타야하는 비행기의 최소 갯수를 출력하는 문제입니다.
입력으로는 무조건 연결그래프만 주어지며, N개의 국가를 모두 연결하기 위해서는 최소 N - 1개의 간선만 있으면 됩니다.
입력만 다받고 N - 1를 출력해줍시다.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | package BOJ.data_structure; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Boj9372 {     static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));     static StringTokenizer st;     static StringBuffer sb = new StringBuffer();     static int N;     static void input() throws Exception {         int M, x;         st = new StringTokenizer(br.readLine());         N = Integer.parseInt(st.nextToken());         M = Integer.parseInt(st.nextToken());         while (M-- > 0) {             st = new StringTokenizer(br.readLine());             x = Integer.parseInt(st.nextToken());             x = Integer.parseInt(st.nextToken());         }         sb.append(N - 1 + "\n");     }     public static void main(String[] args) throws Exception {         st = new StringTokenizer(br.readLine());         int tc = Integer.parseInt(st.nextToken());         while (tc-- > 0) {             input();         }         System.out.println(sb.toString());     } } | cs | 
'algorithm > data-structure' 카테고리의 다른 글
| boj 21939 문제 추천 시스템 Version 1 (0) | 2022.02.11 | 
|---|---|
| boj 17299 오등큰수 (0) | 2021.02.22 | 
| boj 1158 요세푸스 문제 (0) | 2021.02.09 | 
| boj 1918 후위 표기식 (0) | 2021.02.05 | 
| boj 1935 후위 표기식2 (0) | 2021.02.05 |