[백준] 1922번:네트워크 연결 (Java 자바)

[백준] 1922번:네트워크 연결 (Java 자바)

반응형

문제

https://www.acmicpc.net/problem/1922

풀이 및 소스코드

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.PriorityQueue; import java.util.StringTokenizer; class Main { public static boolean union(int x, int y) { x = find(x); y = find(y); if(x == y) return false; p[x] = y; return true; } public static int find(int x) { if(p[x]==x) return x; return p[x]=find(p[x]); } public static void make_set(int n) { for(int i=1;i<=n;i++) { p[i] = i; } } static int[] p; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int n = Integer.parseInt(br.readLine()); int m = Integer.parseInt(br.readLine()); p = new int[n+1]; PriorityQueue q = new PriorityQueue<>(); for(int i=0;i{ int x, y, w; public Node(int x, int y, int w) { super(); this.x = x; this.y = y; this.w = w; } @Override public int compareTo(Node o) { // TODO Auto-generated method stub return this.w-o.w; } }

반응형

from http://jainn.tistory.com/257 by ccl(A) rewrite - 2021-09-08 02:01:10