From fa8892c96ce8c2bc82b0dd519fae79a3a07ac2df Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:19:12 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[20250211]=20BOJ=20/=20=EA=B3=A8=EB=93=9C3?= =?UTF-8?q?=20/=20=EC=9B=9C=ED=99=80=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../26 BOJ G3 \354\233\234\355\231\200.md" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" diff --git "a/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" "b/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" new file mode 100644 index 00000000..26a2cdfc --- /dev/null +++ "b/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" @@ -0,0 +1,77 @@ +```java +import java.util.*; +import java.io.*; + +public class boj1865 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static void bwEnd() throws Exception {bw.flush(); bw.close();} + static ArrayList road; + static int N; + + public static void main(String[] args) throws Exception { + nextLine(); + int TC = nextInt(); + for (int tc = 0; tc < TC; tc++) { + nextLine(); + N = nextInt(); //지점의 수 + int M = nextInt(); //도로의 갯수 + int W = nextInt(); //웜홀의 갯수 + road = new ArrayList<>(N+1); + + int S, E, T; + for (int i = 0 ; i < M+W; i++) { + nextLine(); + S = nextInt(); + E = nextInt(); + T = nextInt(); + if (i < M) { + road.add(new Road(S, E, T)); + road.add(new Road(E, S, T)); + } else { + road.add(new Road(S, E, -1*T)); + } + } + + if (bfs()) bw.write("YES"+"\n"); + else bw.write("NO"+"\n"); + } + bwEnd(); + } + + // 음수 사이클 존재하면 true 반환 + static boolean bfs() { + int[] time = new int[N+1]; + Arrays.fill(time, 10001); + time[1] = 0; + + for (int i = 0; i < N; i++) { //N-1번 반복 + N번째 처리 + for (int j = 0; j < road.size(); j++) { //간선 확인 + Road r = road.get(j); + if (i == N-1) { + if (time[r.e] > time[r.s]+r.t) return true; + continue; + } + time[r.e] = Math.min(time[r.e], time[r.s]+r.t); + } + } + return false; + } + + static class Road { + int s; + int e; + int t; + public Road(int s, int e, int t) { + this.s = s; + this.e = e; + this.t = t; + } + } +} + +``` From 9d51f5e6e7feb6d3d79b2cc0a26198fe622063b0 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:19:47 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Delete=20suyeun84/202502/26=20BOJ=20G3=20?= =?UTF-8?q?=EC=9B=9C=ED=99=80.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../26 BOJ G3 \354\233\234\355\231\200.md" | 77 ------------------- 1 file changed, 77 deletions(-) delete mode 100644 "suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" diff --git "a/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" "b/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" deleted file mode 100644 index 26a2cdfc..00000000 --- "a/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" +++ /dev/null @@ -1,77 +0,0 @@ -```java -import java.util.*; -import java.io.*; - -public class boj1865 { - static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - static StringTokenizer st; - - static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} - static int nextInt() {return Integer.parseInt(st.nextToken());} - static void bwEnd() throws Exception {bw.flush(); bw.close();} - static ArrayList road; - static int N; - - public static void main(String[] args) throws Exception { - nextLine(); - int TC = nextInt(); - for (int tc = 0; tc < TC; tc++) { - nextLine(); - N = nextInt(); //지점의 수 - int M = nextInt(); //도로의 갯수 - int W = nextInt(); //웜홀의 갯수 - road = new ArrayList<>(N+1); - - int S, E, T; - for (int i = 0 ; i < M+W; i++) { - nextLine(); - S = nextInt(); - E = nextInt(); - T = nextInt(); - if (i < M) { - road.add(new Road(S, E, T)); - road.add(new Road(E, S, T)); - } else { - road.add(new Road(S, E, -1*T)); - } - } - - if (bfs()) bw.write("YES"+"\n"); - else bw.write("NO"+"\n"); - } - bwEnd(); - } - - // 음수 사이클 존재하면 true 반환 - static boolean bfs() { - int[] time = new int[N+1]; - Arrays.fill(time, 10001); - time[1] = 0; - - for (int i = 0; i < N; i++) { //N-1번 반복 + N번째 처리 - for (int j = 0; j < road.size(); j++) { //간선 확인 - Road r = road.get(j); - if (i == N-1) { - if (time[r.e] > time[r.s]+r.t) return true; - continue; - } - time[r.e] = Math.min(time[r.e], time[r.s]+r.t); - } - } - return false; - } - - static class Road { - int s; - int e; - int t; - public Road(int s, int e, int t) { - this.s = s; - this.e = e; - this.t = t; - } - } -} - -``` From b0f39c711c5f9b2ecc73581d23f8fac75d64d1b1 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:20:54 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[20250226]=20BOJ=20/=20=EA=B3=A8=EB=93=9C3?= =?UTF-8?q?=20/=20=EC=9B=9C=ED=99=80=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../26 BOJ G3 \354\233\234\355\231\200.md" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" diff --git "a/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" "b/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" new file mode 100644 index 00000000..26a2cdfc --- /dev/null +++ "b/suyeun84/202502/26 BOJ G3 \354\233\234\355\231\200.md" @@ -0,0 +1,77 @@ +```java +import java.util.*; +import java.io.*; + +public class boj1865 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static void bwEnd() throws Exception {bw.flush(); bw.close();} + static ArrayList road; + static int N; + + public static void main(String[] args) throws Exception { + nextLine(); + int TC = nextInt(); + for (int tc = 0; tc < TC; tc++) { + nextLine(); + N = nextInt(); //지점의 수 + int M = nextInt(); //도로의 갯수 + int W = nextInt(); //웜홀의 갯수 + road = new ArrayList<>(N+1); + + int S, E, T; + for (int i = 0 ; i < M+W; i++) { + nextLine(); + S = nextInt(); + E = nextInt(); + T = nextInt(); + if (i < M) { + road.add(new Road(S, E, T)); + road.add(new Road(E, S, T)); + } else { + road.add(new Road(S, E, -1*T)); + } + } + + if (bfs()) bw.write("YES"+"\n"); + else bw.write("NO"+"\n"); + } + bwEnd(); + } + + // 음수 사이클 존재하면 true 반환 + static boolean bfs() { + int[] time = new int[N+1]; + Arrays.fill(time, 10001); + time[1] = 0; + + for (int i = 0; i < N; i++) { //N-1번 반복 + N번째 처리 + for (int j = 0; j < road.size(); j++) { //간선 확인 + Road r = road.get(j); + if (i == N-1) { + if (time[r.e] > time[r.s]+r.t) return true; + continue; + } + time[r.e] = Math.min(time[r.e], time[r.s]+r.t); + } + } + return false; + } + + static class Road { + int s; + int e; + int t; + public Road(int s, int e, int t) { + this.s = s; + this.e = e; + this.t = t; + } + } +} + +```