From d01fd41ad2b3ee7ee8ac205bfdab277a201951b1 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 9 Sep 2025 11:23:57 +0900 Subject: [PATCH] =?UTF-8?q?[20250909]=20BOJ=20/=20P2=20/=20Double=20Up=202?= =?UTF-8?q?=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- khj20006/202509/09 BOJ P2 Double Up 2.md | 174 +++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 khj20006/202509/09 BOJ P2 Double Up 2.md diff --git a/khj20006/202509/09 BOJ P2 Double Up 2.md b/khj20006/202509/09 BOJ P2 Double Up 2.md new file mode 100644 index 00000000..8d959ddf --- /dev/null +++ b/khj20006/202509/09 BOJ P2 Double Up 2.md @@ -0,0 +1,174 @@ +```java +import java.io.*; +import java.util.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) + nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, M; + static int[] next, root, indeg; + static long[] cnt, origin; + static List> cycles; + static boolean[] isCycle; + + static int f(int x) {return x==root[x] ? x : (root[x]=f(root[x]));} + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + M = io.nextInt(); + next = new int[M]; + origin = new long[M]; + root = new int[M]; + cnt = new long[M]; + indeg = new int[M]; + for(int i=0;i(); + boolean[] vis = new boolean[M]; + boolean[] vvis = new boolean[M]; + int[] par = new int[M]; + for(int i=0;i list = new ArrayList<>(); + int r = next[n]; + list.add(r); + while(n != r) { + list.add(n); + n = par[n]; + } + cycles.add(list); + } + + isCycle = new boolean[M]; + for(List list : cycles) { + for(int i:list) isCycle[i] = true; + } + + Queue q = new ArrayDeque<>(); + for(int i=0;i list : cycles) { + long sum = 0, s = 0; + int zeroCnt = 0; + for(int i=0;i S) ans = res; + else ans = Math.min(ans, res); + S = s; + continue; + } + + long res = sum; + for(int i=0;i S) ans = res; + else ans = Math.min(ans, res); + S = s; + } + + io.write(S + " " + ans + "\n"); + + io.close(); + + } + +} +```