diff --git "a/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-21276] \352\263\204\353\263\264 \353\263\265\354\233\220\352\260\200 \355\230\270\354\204\235.md" "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-21276] \352\263\204\353\263\264 \353\263\265\354\233\220\352\260\200 \355\230\270\354\204\235.md" new file mode 100644 index 0000000..ef39478 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-21276] \352\263\204\353\263\264 \353\263\265\354\233\220\352\260\200 \355\230\270\354\204\235.md" @@ -0,0 +1,95 @@ +```java +import java.util.*; +import java.io.*; + +public 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 N, M; + static TreeMap> V; + static TreeMap> R; + static TreeMap D; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception { + + N = nextInt(); + V = new TreeMap<>(); + D = new TreeMap<>(); + R = new TreeMap<>(); + for(int i=1;i<=N;i++) { + String a = nextToken(); + V.put(a, new ArrayList<>()); + R.put(a, new ArrayList<>()); + D.put(a, 0); + } + + for(M = nextInt(); M-->0;){ + String a = nextToken(), b = nextToken(); + V.get(b).add(a); + D.put(a, D.get(a) + 1); + } + + } + + static void solve() throws Exception { + + List roots = new ArrayList<>(); + TreeMap Z = new TreeMap<>(); + for(String key : D.keySet()) Z.put(key, D.get(key) == 0); + + for(String key : D.keySet()) if(Z.get(key)) { + roots.add(key); + Queue Q = new LinkedList<>(); + Q.offer(key); + while(!Q.isEmpty()) { + String n = Q.poll(); + for(String i : V.get(n)) { + D.put(i, D.get(i) - 1); + if(D.get(i) == 0) { + R.get(n).add(i); + Q.offer(i); + } + } + } + } + bw.write(roots.size() + "\n"); + for(String i:roots) bw.write(i + " "); + bw.write("\n"); + + for(String key:R.keySet()) { + bw.write(key + " " + R.get(key).size() + " "); + Collections.sort(R.get(key)); + for(String i:R.get(key)) bw.write(i + " "); + bw.write("\n"); + } + + + } + +} +``` diff --git "a/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-2306] \354\234\240\354\240\204\354\236\220.md" "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-2306] \354\234\240\354\240\204\354\236\220.md" new file mode 100644 index 0000000..f3c2b28 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-2306] \354\234\240\354\240\204\354\236\220.md" @@ -0,0 +1,83 @@ +```java +import java.util.*; +import java.io.*; + +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(""); + } + + void nextLine() throws Exception { + st = new StringTokenizer(br.readLine()); + } + + 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 char[] A; + static int[][] dp; + static int N; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + A = ("?" + io.nextToken()).toCharArray(); + N = A.length-1; + dp = new int[N+1][N+1]; + + } + + static void solve() throws Exception { + + for(int k=1;k A, B, C; + static boolean[] RB; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception { + + A = new ArrayList<>(); + B = new ArrayList<>(); + C = new ArrayList<>(); + char[] temp = nextToken().toCharArray(); + for(int i=0;i C.get(j)) j++; + if(j < C.size()) { + ans++; + RB[i] = true; + j++; + } + } + + for(int i=0, j=0;i B.get(j))) j++; + if(j < B.size()) { + ans++; + j++; + } + } + + bw.write(ans + "\n"); + + } + +} +``` diff --git "a/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-2637] \354\236\245\353\202\234\352\260\220 \354\241\260\353\246\275.md" "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-2637] \354\236\245\353\202\234\352\260\220 \354\241\260\353\246\275.md" new file mode 100644 index 0000000..7a12b3d --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-2637] \354\236\245\353\202\234\352\260\220 \354\241\260\353\246\275.md" @@ -0,0 +1,84 @@ +```java +import java.util.*; +import java.io.*; + +public 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 N, M; + static int[][] A; + static List[] V; + static int[] deg; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + A = new int[N+1][N+1]; + V = new List[N+1]; + for(int i=1;i<=N;i++) V[i] = new ArrayList<>(); + deg = new int[N+1]; + for(int i=0;i Q = new LinkedList<>(); + for(int i=1;i<=N;i++) if(isBasic[i]) { + for(int[] j:V[i]) { + int x = j[0], c = j[1]; + if(isBasic[i]) A[x][i] = c; + if(--deg[x] == 0) Q.offer(x); + } + } + + while(!Q.isEmpty()) { + int now = Q.poll(); + for(int[] j:V[now]) { + int x = j[0], c = j[1]; + for(int i=1;i<=N;i++) if(isBasic[i]) A[x][i] += A[now][i] * c; + if(--deg[x] == 0) Q.offer(x); + } + } + + for(int i=1;i<=N;i++) if(A[N][i] != 0) { + bw.write(i + " " + A[N][i] + "\n"); + } + + } + +} +``` diff --git "a/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-6209] \354\240\234\354\236\220\353\246\254 \353\251\200\353\246\254\353\233\260\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-6209] \354\240\234\354\236\220\353\246\254 \353\251\200\353\246\254\353\233\260\352\270\260.md" new file mode 100644 index 0000000..6a09d04 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_20\354\243\274\354\260\250/[BOJ-6209] \354\240\234\354\236\220\353\246\254 \353\251\200\353\246\254\353\233\260\352\270\260.md" @@ -0,0 +1,71 @@ +```java +import java.util.*; +import java.io.*; + +public 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 D, N, M; + static int[] A; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + D = nextInt(); + N = nextInt(); + M = nextInt(); + A = new int[N]; + for(int i=0;i>1; + while(s>1; + } + bw.write(m + "\n"); + + } + + static boolean check(int limit) { + int last = 0, cnt = 0; + for(int i=0;i= limit) { + last = A[i]; + cnt++; + } + return cnt >= M; + } + +} +```