diff --git a/code_study/Baekjoon/python/31868.py b/code_study/Baekjoon/python/31868.py new file mode 100644 index 0000000..179e946 --- /dev/null +++ b/code_study/Baekjoon/python/31868.py @@ -0,0 +1,2 @@ +N, K = map(int, input().split()) +print(K//(2**(N-1))) diff --git a/code_study/Baekjoon/swift/1967.swift b/code_study/Baekjoon/swift/1967.swift new file mode 100644 index 0000000..bc11e6e --- /dev/null +++ b/code_study/Baekjoon/swift/1967.swift @@ -0,0 +1,53 @@ +func findNode(from start: Int, of graph: [[(node: Int, weight: Int)]]) -> (node: Int, length: Int) { + var result = (node: start, length: 0) + + var visited = Array(repeating: false, count: graph.count) + var stack = [(node: Int, length: Int)]() + stack.append(result) + visited[start] = true + + while !stack.isEmpty { + if let (now, cur_len) = stack.popLast() + { + if cur_len > result.length { + result = (node: now, length: cur_len) + } + + for next in graph[now] { + if !visited[next.node] { + visited[next.node] = true + stack.append((node: next.node, length: cur_len + next.weight)) + } + } + } + } + + return result +} + +if let N = Int(readLine() ?? "0") +{ + if N == 1 { + print(0) + } + else { + var graph = Array(repeating: [(node: Int, weight: Int)](), count: N+1) + + for _ in 0..