Skip to content

Commit

Permalink
Merge pull request #78 from AlgoLeadMe/22-alstjr7437
Browse files Browse the repository at this point in the history
22-alstjr7437
  • Loading branch information
tgyuuAn authored May 10, 2024
2 parents 1e75787 + 598d8d9 commit a13af6f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Foundation

let input = readLine()!.split(separator:
" ").map{ Int($0)!}

let n = input[0] , m = input[1]

var graph : [[Int]] = Array(repeating: [], count: n + 1)
var visited : [Bool] = Array(repeating: false, count: n + 1)
var result : Int = 0

for _ in 0..<m {
let tmp = readLine()!.split(separator: " ").map { Int($0)!}
graph[tmp[0]].append(tmp[1])
graph[tmp[1]].append(tmp[0])
}

func bfs(start: Int){
visited[start] = true
var queue: [Int] = [start]

var idx : Int = 0

while idx < queue.count{
let current = queue[idx]

idx += 1
for i in graph[current]{
if visited[i] == false {
queue.append(i)
visited[i] = true
}
}
}
}

for i in 1...n{
if visited[i] == false {
bfs(start : i)
result += 1
}
}

print(result)
3 changes: 2 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
| 18์ฐจ์‹œ | 2024.03.23 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/1753">์ตœ๋‹จ ๊ฒฝ๋กœ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/66 |
| 19์ฐจ์‹œ | 2024.03.27 | ๋ฌธ์ž์—ด | <a href="https://www.acmicpc.net/problem/5525">IOIOI</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/67 |
| 20์ฐจ์‹œ | 2024.04.03 | BFS | <a href="https://www.acmicpc.net/problem/1697">์ˆจ๋ฐ”๊ผญ์งˆ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 |
| 21์ฐจ์‹œ | 2024.04.06 | ๋น„ํŠธ๋งˆ์Šคํ‚น | <a href="https://www.acmicpc.net/problem/11723">์ง‘ํ•ฉ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/74 |
| 21์ฐจ์‹œ | 2024.04.06 | ๋น„ํŠธ๋งˆ์Šคํ‚น | <a href="https://www.acmicpc.net/problem/11723">์ง‘ํ•ฉ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/74 |
| 22์ฐจ์‹œ | 2024.04.13 | BFS | <a href="https://www.acmicpc.net/problem/11724">์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 |

0 comments on commit a13af6f

Please sign in to comment.