Repository: Alom-codingTest/alom-codingTest-25-1
Pull request #64: 상급반 / 정지태 / 숨바꼭질_3-13549, 효율적인_해킹-1325, 숫자고르기-2668,  움직이는_미로_탈출-16954
Author: login: JtJint
Labels: name: 그래프 탐색
name: !상급반
Created: 2025-04-04T14:41:16Z | Merged: 2025-04-08T04:41:09Z



Diff:
diff --git "a/week4/graph_traversal/\354\210\250\353\260\224\352\274\255\354\247\210_3/JtJint.py" "b/week4/graph_traversal/\354\210\250\353\260\224\352\274\255\354\247\210_3/JtJint.py"
new file mode 100644
index 00000000..f558c761
--- /dev/null
+++ "b/week4/graph_traversal/\354\210\250\353\260\224\352\274\255\354\247\210_3/JtJint.py"
@@ -0,0 +1,29 @@
+import sys
+input = sys.stdin.readline
+from collections import deque
+visited = [0]*100001
+n, k = map(int, input().strip().split(" "))
+Q = deque()
+
+Q.append((n,0))
+visited[n] = 1
+results = []
+while Q :
+    n, time = Q.popleft()
+    if n == k :
+        results.append(time)
+
+    if 2*n <= 100000:
+        if visited[2*n] == 0 :
+            visited[2*n] = 1
+            Q.append((2*n,time)) 
+    if n-1 >= 0 :
+        if visited[n-1] == 0 :
+            visited[n-1] = 1
+            Q.append((n-1, time+1))        
+    if n+1 <= 100000 :
+        if visited[n+1] == 0 :
+            visited[n+1] = 1
+            Q.append((n+1, time+1))
+        
+print(min(results))
\ No newline at end of file
diff --git "a/week4/graph_traversal/\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260/JtJint.py" "b/week4/graph_traversal/\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260/JtJint.py"
new file mode 100644
index 00000000..037d710f
--- /dev/null
+++ "b/week4/graph_traversal/\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260/JtJint.py"
@@ -0,0 +1,37 @@
+import sys
+input = sys.stdin.readline
+from collections import deque
+n = int(input())
+array = [0]*(n+1)
+
+for i in range(n) :
+    array[i+1] = int(input())
+    
+result = []
+set1 = set()
+for i in range(1,n+1) :
+    if array[i] == i :
+        result.append(i)
+    Q = deque()
+    Q.append(i)
+    tmp = []
+    visited = [0]*(n+1)
+    visited[i] = 1
+    while Q :
+        elem = Q.popleft()
+        if array[elem] == i :
+            for k in range(len(tmp)):
+                result.append(tmp[k])
+            break
+        if visited[array[elem]] == 0 :
+            visited[array[elem]] = 1
+            tmp.append(array[elem])
+            Q.append(array[elem])
+            
+            
+result.sort()
+for i in result :
+    set1.add(i)
+print(len(set1))
+for i in set1 :
+    print(i)
\ No newline at end of file
diff --git "a/week4/graph_traversal/\354\233\200\354\247\201\354\235\264\353\212\224_\353\257\270\353\241\234_\355\203\210\354\266\234/JtJint.py" "b/week4/graph_traversal/\354\233\200\354\247\201\354\235\264\353\212\224_\353\257\270\353\241\234_\355\203\210\354\266\234/JtJint.py"
new file mode 100644
index 00000000..1914aa37
--- /dev/null
+++ "b/week4/graph_traversal/\354\233\200\354\247\201\354\235\264\353\212\224_\353\257\270\353\241\234_\355\203\210\354\266\234/JtJint.py"
@@ -0,0 +1,53 @@
+import sys
+input = sys.stdin.readline
+from collections import deque
+chess = deque()
+visited = []
+y,x = 7,0
+
+for _ in range(8) :
+    visited.append([0]*8)
+    chess.append(input().strip())
+    
+changableX = [-1,0,1]
+changalbeY = [-1,0,1]
+Q = deque()
+visited[7][0] = 1
+Q.append((y,x, chess))
+
+result = 0
+while Q :
+    posY, posX , c = Q.popleft()
+    tmpChess = deque()
+    for i in range(8) :
+        tmpChess.append(c[i])
+    # print(tmpChess)
+    ableList = []
+    flag = 0
+    for i in range(8) :
+        if tmpChess[i].count('#') == 0 :
+            flag +=1
+            
+    if flag ==8 or posY == 0 and posX == 7 :
+        result = 1
+        break
+    
+    for i in changableX :
+        for j in changalbeY :
+            if (0<= posY+j <= 7 and 0<=posX+i<= 7)and tmpChess[posY+j][posX+i] == '.':
+                # visited[posY+j][posX] = 1
+                # Q.append((posY,posX,tmpChess))
+                ableList.append((posY+j,posX+i))
+    
+    tmpChess.pop()
+    tmpChess.appendleft('........')
+    
+    for i, j in ableList :
+        if tmpChess[i][j] == '.' :
+            Q.append((i,j,tmpChess))
+    
+            
+    
+    
+print(result)
+
diff --git "a/week4/graph_traversal/\355\232\250\354\234\250\354\240\201\354\235\270_\355\225\264\355\202\271/JtJint.py" "b/week4/graph_traversal/\355\232\250\354\234\250\354\240\201\354\235\270_\355\225\264\355\202\271/JtJint.py"
new file mode 100644
index 00000000..aab252a5
--- /dev/null
+++ "b/week4/graph_traversal/\355\232\250\354\234\250\354\240\201\354\235\270_\355\225\264\355\202\271/JtJint.py"
@@ -0,0 +1,39 @@
+import sys
+from collections import deque
+
+input = sys.stdin.readline
+
+n, m = map(int, input().split())
+
+graph = [[] for _ in range(n + 1)]
+for _ in range(m):
+    a, b = map(int, input().split())
+    graph[b].append(a)  # b->a 해킹 가능
+
+def bfs(start):
+    queue = deque([start])
+    visited = [False] * (n + 1)
+    visited[start] = True
+    count = 1  # 자기 자신도 포함
+
+    while queue:
+        node = queue.popleft()
+        for next_node in graph[node]:
+            if not visited[next_node]:
+                visited[next_node] = True
+                queue.append(next_node)
+                count += 1
+    return count
+
+maxCnt = 0
+result = []
+for i in range(1, n + 1):
+    count = bfs(i)
+
+    if count > maxCnt:
+        max_hack = count
+        result = [i]
+    elif count == maxCnt:
+        result.append(i)
+
+print(*result)


Reviews:
user: login: AppliedAlpha
body: 리뷰 완료하였습니다. 수고하셨습니다. 
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T06:31:16Z
user: login: copilot-pull-request-reviewer[bot]
body: 

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.




state: COMMENTED
author_association: NONE
submitted_at: 2025-04-07T06:33:05Z

Review comments:
diff_hunk: @@ -0,0 +1,29 @@
+import sys
+input = sys.stdin.readline
+from collections import deque
+visited = [0]*100001
path: week4/graph_traversal/숨바꼭질_3/JtJint.py
user: login: AppliedAlpha
body: visited 배열에 0, 1밖에 없다면 False, True의 bool 타입 값을 사용하는 것이 조금 더 유리합니다.
created_at: 2025-04-07T06:28:41Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,53 @@
+import sys
+input = sys.stdin.readline
+from collections import deque
+chess = deque()
+visited = []
+y,x = 7,0
+
+for _ in range(8) :
+    visited.append([0]*8)
+    chess.append(input().strip())
+    
+changableX = [-1,0,1]
+changalbeY = [-1,0,1]
+Q = deque()
+visited[7][0] = 1
+Q.append((y,x, chess))
+
+result = 0
+while Q :
+    posY, posX , c = Q.popleft()
+    tmpChess = deque()
+    for i in range(8) :
+        tmpChess.append(c[i])
+    # print(tmpChess)
+    ableList = []
+    flag = 0
+    for i in range(8) :
+        if tmpChess[i].count('#') == 0 :
+            flag +=1
+            
+    if flag ==8 or posY == 0 and posX == 7 :
+        result = 1
+        break
+    
+    for i in changableX :
+        for j in changalbeY :
+            if (0<= posY+j <= 7 and 0<=posX+i<= 7)and tmpChess[posY+j][posX+i] == '.':
+                # visited[posY+j][posX] = 1
+                # Q.append((posY,posX,tmpChess))
+                ableList.append((posY+j,posX+i))
+    
+    tmpChess.pop()
+    tmpChess.appendleft('........')
path: week4/graph_traversal/움직이는_미로_탈출/JtJint.py
user: login: AppliedAlpha
body: 체스판을 string들의 list로 만든 점이 인상 깊습니다.
created_at: 2025-04-07T06:30:52Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,39 @@
+import sys
+from collections import deque
+
+input = sys.stdin.readline
+
+n, m = map(int, input().split())
+
+graph = [[] for _ in range(n + 1)]
+for _ in range(m):
+    a, b = map(int, input().split())
+    graph[b].append(a)  # b->a 해킹 가능
+
+def bfs(start):
+    queue = deque([start])
+    visited = [False] * (n + 1)
+    visited[start] = True
+    count = 1  # 자기 자신도 포함
+
+    while queue:
+        node = queue.popleft()
+        for next_node in graph[node]:
+            if not visited[next_node]:
+                visited[next_node] = True
+                queue.append(next_node)
+                count += 1
+    return count
+
+maxCnt = 0
+result = []
+for i in range(1, n + 1):
+    count = bfs(i)
+
+    if count > maxCnt:
+        max_hack = count
path: week4/graph_traversal/효율적인_해킹/JtJint.py
user: login: Copilot
body: The variable 'maxCnt' is not updated when a higher count is found (using 'max_hack' instead). Update 'maxCnt' to 'count' to correctly track the maximum hacking count.
```suggestion
        maxCnt = count
```
created_at: 2025-04-07T06:33:04Z
author_association: NONE
diff_hunk: @@ -0,0 +1,53 @@
+import sys
+input = sys.stdin.readline
+from collections import deque
+chess = deque()
+visited = []
+y,x = 7,0
+
+for _ in range(8) :
+    visited.append([0]*8)
+    chess.append(input().strip())
+    
+changableX = [-1,0,1]
+changalbeY = [-1,0,1]
path: week4/graph_traversal/움직이는_미로_탈출/JtJint.py
user: login: Copilot
body: [nitpick] The variable name 'changalbeY' appears to be a typo; consider renaming it to 'changableY' for consistency.
```suggestion
changableY = [-1,0,1]
```
created_at: 2025-04-07T06:33:05Z
author_association: NONE

PR comments:
user: login: JtJint
created_at: 2025-04-04T14:44:09Z
body: 움직이는 미로탈출 45m을 45h로 잘못커밋했습니다.
author_association: CONTRIBUTOR
user: login: JtJint
created_at: 2025-04-04T16:06:26Z
body: 해킹문제 코드 수정 2차 커밋으로 되어있습니다.
author_association: CONTRIBUTOR