๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ

[์ž๋ฐ”] ๋ฐฑ์ค€ 9372 - ์ƒ๊ทผ์ด์˜ ์—ฌํ–‰

by applemango2021 2020. 12. 4.

์ข‹์€ ๋ฌธ์ œ๋‹ค.

๋„ˆ๋ฌด ์–ด๋ ต๊ฒŒ๋งŒ ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ์ •๋‹ต์€ ๋น„ํ–‰๊ธฐ์˜ ์ข…๋ฅ˜์— ์žˆ์—ˆ๋‹ค.

 

๋งŒ์•ฝ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •๋‹ต์ด ๋น„ํ–‰๊ธฐ๋ฅผ ํƒ€๋Š” ์ตœ์†Œ ํšŸ์ˆ˜๋‚˜ ์ตœ๋‹จ ๊ฑฐ๋ฆฌ์˜€๋‹ค๋ฉด ๋…ธ๋“œ ๋งŒ๋“ค๊ณ , ๊ฐ„์„  ๋งŒ๋“ค๊ณ  ๊ทธ๋ž˜์•ผ ํ–ˆ๊ฒ ์ง€๋งŒ 

๋น„ํ–‰๊ธฐ์˜ ์ข…๋ฅ˜๋ฅผ ๊ตฌํ•˜๋ผ๊ณ  ํ–ˆ์œผ๋‹ˆ N-1์ด ์ •๋‹ต์ด๋‹ค. 

 

๋…ธ๋“œ์™€ ๊ฐ„์„ ์˜ ๊ด€๊ณ„๋ฅผ ์•Œ๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋Š” ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™๋‹ค.

๋…ธ๋“œ N๊ฐœ๊ฐ€ ์žˆ์œผ๋ฉด ๋…ธ๋“œ๋ผ๋ฆฌ ๋ชจ๋‘ ์—ฐ๊ฒฐ๋˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ตœ์†Œ N-1๊ฐœ์˜ ๊ฐ„์„ ์ด ํ•„์š”ํ•˜๋‹ค. 

 

๋‹ต์œผ๋กœ๋Š” N-1๋งŒ ์ถœ๋ ฅํ•˜๋ฉด ๋˜์ง€๋งŒ, ์ž…๋ ฅ ๋“ค์–ด์˜ค๋Š” ๊ฐ’์€ ๋ฐ›์•„์ค˜์•ผ ํ•˜๋‹ˆ๊นŒ StringTokenizer์œผ๋กœ ๋ฐ›์•˜๋‹ค.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{

	public static void main(String[] args) throws IOException 
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine().trim());
		
		int T = Integer.parseInt(st.nextToken().trim());
		for(int t=0;t<T;t++)
		{
			int N, M;
			st = new StringTokenizer(br.readLine().trim());
			N = Integer.parseInt(st.nextToken());
			M = Integer.parseInt(st.nextToken());
			
			for(int m=0;m<M;m++)
			{
				st = new StringTokenizer(br.readLine());
			}
			System.out.println(N-1);
		}
	}
}