From 49adcfac915b07f758b5a89929ac61fc00a83c4c Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 25 Mar 2026 18:08:47 +0900 Subject: [PATCH] =?UTF-8?q?[20260325]=20BOJ=20/=20P1=20/=20Railway=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- khj20006/202603/25 BOJ P1 Railway.md | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 khj20006/202603/25 BOJ P1 Railway.md diff --git a/khj20006/202603/25 BOJ P1 Railway.md b/khj20006/202603/25 BOJ P1 Railway.md new file mode 100644 index 00000000..2c24ed48 --- /dev/null +++ b/khj20006/202603/25 BOJ P1 Railway.md @@ -0,0 +1,90 @@ +```java +import java.io.*; +import java.util.*; + +public class BOJ22197 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static int N, M, K; + static List[] tree; + static TreeMap[] map; + static int[] size; + static int answerCount = 0; + static boolean[] isAnswer; + + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + tree = new List[N+1]; + for(int i=1;i<=N;i++) { + tree[i] = new ArrayList<>(); + } + + for(int i=1;i(); + } + size = new int[M]; + for(int i=0;i= K) { + answerCount++; + isAnswer[edgeNum] = true; + } + + if(map[cur].size() < map[nxt].size()) { + TreeMap temp = map[cur]; + map[cur] = map[nxt]; + map[nxt] = temp; + } + + for(int key : map[nxt].keySet()) { + int newVal = map[cur].getOrDefault(key, 0) + map[nxt].get(key); + if(newVal != size[key]) { + map[cur].put(key, newVal); + } + else if(map[cur].containsKey(key)) { + map[cur].remove(key); + } + } + } + } +} +```