Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

김지훈 : boj 11403 경로 찾기 #247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions hoonti06/BOJ/11000/11403/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.io.*;
import java.util.*;

public class Main {
static int N;
static int[][] edge;

static void solution() {
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (edge[i][k] == 0 || edge[k][j] == 0)
continue;

edge[i][j] = 1;
}
}
}
}
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

N = Integer.parseInt(in.readLine());
edge = new int[N][N];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(in.readLine(), " ");
for (int j = 0; j < N; j++)
edge[i][j] = Integer.parseInt(st.nextToken());
}

solution();

StringBuilder sb = new StringBuilder();
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
sb.append(edge[i][j]).append(" ");
sb.append("\n");
}
System.out.print(sb);
}
}

23 changes: 23 additions & 0 deletions hoonti06/BOJ/11000/11403/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## 🅰 설계

* floyd-warshall 알고리즘을 활용하여 경유지 k를 거쳐 i에서 j까지 갈 수 있는 지를 확인합니다.

```java
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (edge[i][k] == 0 || edge[k][j] == 0)
continue;

edge[i][j] = 1;
}
}
}
```



## ✅ 후기

- 쌤에게 배운 경출도를 적용했습니다.
- 3중 for문의 정확한 작용 방식이 기억이 나지 않습니다.