[백준] 16202번:MST 게임 (Java 자바)

[백준] 16202번:MST 게임 (Java 자바)

반응형

문제

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

풀이 및 소스코드

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; 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; 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()); Node[] info = new Node[m]; for(int i=1;i<=m;i++) { st = new StringTokenizer(br.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); info[i-1] = new Node(x, y, i); } for(int t=0;t q = new LinkedList(); //넣을 후보들 넣기 make_set(n); int res = 0; for(int i=t;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/258 by ccl(A) rewrite - 2021-09-08 09:26:56