diff --git a/khj20006/202503/27 BOJ G2 Secret Milk Pipes.md b/khj20006/202503/27 BOJ G2 Secret Milk Pipes.md new file mode 100644 index 00000000..48167a69 --- /dev/null +++ b/khj20006/202503/27 BOJ G2 Secret Milk Pipes.md @@ -0,0 +1,106 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int W, P; + static int[][] Edges; + + static List[] V; + static int[] r; + + static int f(int x) {return x==r[x] ? x : (r[x]=f(r[x]));} + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + W = nextInt(); + P = nextInt(); + Edges = new int[P][3]; + for(int i=0;i(); + r[i] = i; + } + + } + + static void solve() throws Exception{ + + + Arrays.sort(Edges, (a,b) -> a[2]-b[2]); + + int mst = 0; + boolean[] used = new boolean[P]; + for(int i=0;i Q = new LinkedList<>(); + boolean[] vis = new boolean[W+1]; + + Q.offer(new int[] {a,0}); + vis[a] = true; + while(!Q.isEmpty()) { + int[] now = Q.poll(); + int n = now[0], t = now[1]; + if(n == b) { + min = Math.min(min, c-t); + break; + } + for(int[] j:V[n]) if(!vis[j[0]]) { + vis[j[0]] = true; + Q.offer(new int[] {j[0],Math.max(t, j[1])}); + } + } + + } + bw.write((mst+min)+"\n"); + } + +} + +```