From 8a3e1216a57060fe73be15f371756809fbe8e951 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 23 Aug 2025 22:55:09 +0900 Subject: [PATCH] =?UTF-8?q?[20250823]=20BOJ=20/=20G2=20/=20=EB=AF=B8?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EB=8F=84=EC=B0=A9=EC=A7=80=20/=20?= =?UTF-8?q?=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\217\204\354\260\251\354\247\200.md" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" diff --git "a/lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" "b/lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" new file mode 100644 index 00000000..b6af36a2 --- /dev/null +++ "b/lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" @@ -0,0 +1,87 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static class Edge { + int to; + int cost; + + public Edge(int to, int cost) { + this.to = to; + this.cost = cost; + } + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + int repeat = Integer.parseInt(br.readLine()); + for(int test=0; test[] graph = new ArrayList[n+1]; + for(int i=1; i<=n; i++) { + graph[i] = new ArrayList<>(); + } + + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int x1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + + for(int i=0; i pq = new PriorityQueue<>((o1, o2) -> Integer.compare(o1.cost, o2.cost)); + pq.offer(new Edge(start, 0)); + dist[start] = 0; + + while(!pq.isEmpty()) { + Edge current = pq.poll(); + + if(dist[current.to] < current.cost) continue; + + for(Edge edge : graph[current.to]) { + int newCost = current.cost + edge.cost; + if(dist[edge.to] <= newCost) continue; + dist[edge.to] = newCost; + pq.offer(new Edge(edge.to, newCost)); + } + } + Arrays.sort(ends); + for(int end : ends) { + int cost = dist[end]; + if(cost%2 == 0) continue; + sb.append(end).append(" "); + } + sb.append("\n"); + } + + + System.out.println(sb.toString().trim()); + } +} +```