트라이를 이용한 풀이 import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { Trie t = new Trie(); int N = sc.nextInt(); ArrayList list = new ArrayList(); for (int i = 0; i < N; i++) { String input = sc.next(); t.insertTrie(input); list.add(i..
반응형
백준
부모의 값을 크기 * -1로 유지하여 최적화 할 수 있는 Weighted Union Find를 이용하여 해결 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class Main { public static int T; public static int F; public static Map map; public static int parent[]; public static int find(i..
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static int N; public static int map[][]; public static int wb[] = new int[2]; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringT..
public class Main { public static int N; public static int M; public static int map[][]; public static boolean visit[][][]; public static int dp[][][]; public static int dx[] = { 1, 0, -1, 0 }; public static int dy[] = { 0, 1, 0, -1 }; public static int min = Integer.MAX_VALUE; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReade..
반응형