on
[백준] 18352번:특정 거리의 도시 찾기 (Java 자바)
[백준] 18352번:특정 거리의 도시 찾기 (Java 자바)
728x90
문제
https://www.acmicpc.net/problem/18352
풀이 및 소스코드
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; StringBuilder sb = new StringBuilder(); st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int k = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken())-1; boolean[] v = new boolean[n]; ArrayList[] g = new ArrayList[n]; PriorityQueue pq = new PriorityQueue<>(); for(int i=0;i(); } for(int i=0;i q = new LinkedList(); q.add(x); int cnt = 0; while(!q.isEmpty()) { int size = q.size(); for(int i=0;i
"); } System.out.println(sb); } }
반응형
from http://jainn.tistory.com/304 by ccl(A) rewrite - 2021-10-19 01:01:49