Skip to content

Commit 62d4c3d

Browse files
committed
update README
1 parent c1ba8ca commit 62d4c3d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
<!-- JAVA_COUNT_START -->
66

7-
- 김성민 폴더의 Java 파일 개수: 0
7+
<!-- - 김성민 폴더의 Java 파일 개수: 0
88
- 김준영 폴더의 Java 파일 개수: 0
99
- 김채하 폴더의 Java 파일 개수: 0
1010
- 양찬열 폴더의 Java 파일 개수: 0
1111
- 오혜윤 폴더의 Java 파일 개수: 0
1212
- 이석철 폴더의 Java 파일 개수: 0
1313
- 제갈도현 폴더의 Java 파일 개수: 0
1414
- 최지호 폴더의 Java 파일 개수: 0
15-
- 한민주 폴더의 Java 파일 개수: 0
15+
- 한민주 폴더의 Java 파일 개수: 0 -->
1616
<!-- JAVA_COUNT_END -->
1717

1818
## week3(0219 ~ 0225)

이석철/P17471.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import java.io.*;
22
import java.util.*;
33

4+
/** 게리맨더링 */
45
public class P17471 {
56
static int n;
67
static int[] people;
@@ -11,26 +12,26 @@ public static void main(String[] args) throws Exception {
1112
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
1213
n = Integer.parseInt(br.readLine());
1314
people = new int[n + 1];
14-
15+
1516
StringTokenizer st = new StringTokenizer(br.readLine());
1617
for (int i = 1; i <= n; i++) {
1718
people[i] = Integer.parseInt(st.nextToken());
1819
}
19-
20+
2021
nodes = new ArrayList[n + 1];
2122
for (int i = 0; i <= n; i++) {
22-
nodes[i] = new ArrayList<>();
23+
nodes[i] = new ArrayList<>();
2324
}
2425

25-
// 인덱싱 맞춰주기 위해 인덱스 0에 0
26+
// 인덱싱 맞춰주기 위해 인덱스 0에 0!
2627
for (int i = 1; i <= n; i++) {
2728
st = new StringTokenizer(br.readLine());
2829
int count = Integer.parseInt(st.nextToken());
2930
for (int j = 0; j < count; j++) {
3031
nodes[i].add(Integer.parseInt(st.nextToken()));
3132
}
3233
}
33-
34+
3435
makeCombination(1, new ArrayList<>());
3536
System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
3637
}
@@ -40,7 +41,7 @@ static void makeCombination(int start, List<Integer> voter1) {
4041
if (!voter1.isEmpty()) {
4142
f(new ArrayList<>(voter1));
4243
}
43-
44+
4445
for (int i = start; i <= n; i++) {
4546
voter1.add(i);
4647
makeCombination(i + 1, voter1);
@@ -56,7 +57,7 @@ static void f(List<Integer> voter1) {
5657
voter2.add(i);
5758
}
5859
}
59-
60+
6061
// bfs 함수 ret 값은 boolean 타입
6162
if (bfs(voter1) && bfs(voter2)) {
6263
int population1 = 0, population2 = 0;
@@ -72,15 +73,15 @@ static void f(List<Integer> voter1) {
7273

7374
// 연결이 되어 있으면 true, 안 되어 있으면 false 리턴
7475
static boolean bfs(List<Integer> voter) {
75-
if (voter.isEmpty())
76+
if (voter.isEmpty())
7677
return false;
77-
78+
7879
Queue<Integer> que = new ArrayDeque<>();
7980
boolean[] visited = new boolean[n + 1]; // 0은 항상 비우기
8081
que.add(voter.get(0));
8182
visited[voter.get(0)] = true;
8283
int count = 1;
83-
84+
8485
while (!que.isEmpty()) {
8586
int node = que.poll();
8687
for (int neighbor : nodes[node]) {
@@ -91,7 +92,7 @@ static boolean bfs(List<Integer> voter) {
9192
}
9293
}
9394
}
94-
95+
9596
return count == voter.size(); // 같으면 연결 된 것
9697
}
9798
}

0 commit comments

Comments
 (0)