Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package baekjoon.dfs_bfs; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.Buffer; | ||
|
||
public class 바닥장식 { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static String[][] graph; | ||
|
||
public static void main(String[] args) throws IOException { | ||
String[] arr = br.readLine().split(" "); | ||
|
||
int n = Integer.parseInt(arr[0]); | ||
int m = Integer.parseInt(arr[1]); | ||
|
||
graph = new String[n][m]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
char[] tile = br.readLine().toCharArray(); | ||
|
||
for (int j = 0; j < m; j++) { | ||
graph[i][j] = String.valueOf(tile[j]); | ||
} | ||
} | ||
|
||
System.out.println("*************************"); | ||
int count = 0; | ||
|
||
for (int i = 0; i < graph.length; i++) { | ||
int tmp = 0; | ||
for (int j = 0; j < graph[i].length; j++) { | ||
if (graph[i][j].equals("|")) { | ||
tmp = 0; | ||
} else { | ||
count++; | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < graph.length; i++) { | ||
int tmp = 0; | ||
for (int j = 0; j < graph[i].length; j++) { | ||
if (graph[j][i].equals("-")) { | ||
tmp = 0; | ||
} else { | ||
count++; | ||
} | ||
} | ||
} | ||
|
||
System.out.println(count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package baekjoon.dfs_bfs; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class 바이러스 { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static int[][] graph; | ||
static boolean[] visited; | ||
static int result; | ||
|
||
public static void main(String[] args) throws IOException { | ||
int n = Integer.parseInt(br.readLine()); | ||
int m = Integer.parseInt(br.readLine()); | ||
|
||
graph = new int[n + 1][n + 1]; | ||
visited = new boolean[n + 1]; | ||
|
||
int startIndex = 1; | ||
|
||
result = 0; | ||
|
||
for (int i = 0; i < m; i++) { | ||
String[] arr = br.readLine().split(" "); | ||
int a = Integer.parseInt(arr[0]); | ||
int b = Integer.parseInt(arr[1]); | ||
|
||
graph[a][b] = graph[b][a] = 1; | ||
} | ||
|
||
dfs(startIndex); | ||
|
||
System.out.println(result); | ||
} | ||
|
||
static void dfs(int startIndex) { | ||
visited[startIndex] = true; | ||
|
||
for (int i = 1; i < graph.length; i++) { | ||
if (graph[startIndex][i] == 1 && !visited[i]) { | ||
result++; | ||
dfs(i); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package baekjoon.dfs_bfs; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
// TODO: 틀림.... | ||
public class 한동이 { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static int[] graph; | ||
static boolean[] visited; | ||
static int result; | ||
static int count; | ||
static int temp; | ||
public static void main(String[] args) throws IOException { | ||
int n = Integer.parseInt(br.readLine()); | ||
|
||
graph = new int[n + 1]; | ||
visited = new boolean[n + 1]; | ||
temp = Integer.MIN_VALUE; | ||
|
||
for (int i = 1; i < graph.length; i++) { | ||
graph[i] = Integer.parseInt(br.readLine()); | ||
} | ||
|
||
for (int i = 1; i <= n; i++) { | ||
visited = new boolean[n + 1]; | ||
dfs(i); | ||
|
||
if (temp < count) { | ||
temp = count; | ||
result = i; | ||
} | ||
|
||
count = 0; | ||
} | ||
|
||
System.out.println(result); | ||
} | ||
|
||
static void dfs(int startIdx) { | ||
visited[startIdx] = true; | ||
|
||
for (int i = 1; i < graph.length; i++) { | ||
if (!visited[graph[i]]) { | ||
count++; | ||
dfs(graph[i]); | ||
} | ||
} | ||
} | ||
} |