From a6c97b96b6bd85073db0e3b5fce337751fe9d5a7 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Fri, 26 Sep 2025 23:47:52 +0900 Subject: [PATCH] 20250926 baekjoon --- code_study/Baekjoon/python/31868.py | 2 ++ code_study/Baekjoon/swift/1967.swift | 53 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 code_study/Baekjoon/python/31868.py create mode 100644 code_study/Baekjoon/swift/1967.swift 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..