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(); + + } + +} +```