baekjoon 20260407

This commit is contained in:
songyc macbook 2026-04-07 21:01:20 +09:00
parent 5cfa8774e1
commit 11b4b82914
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,11 @@
res = []
for _ in range(int(input())) :
a, b, t = 0, 0, int(input())
for _ in range(t) :
line = input().rstrip()
if line == "R S" or line == "S P" or line == "P R" :
a += 1
elif line == "S R" or line == "P S" or line == "R P" :
b += 1
res.append("TIE" if a == b else "Player 1" if a > b else "Player 2")
print('\n'.join(res))

View File

@ -0,0 +1,34 @@
func main() {
guard let N = Int(readLine() ?? "") else { return }
var graph: [[Int]] = Array(repeating: [], count: N+1)
for _ in 1..<N {
guard let input = readLine() else { return }
let uv = input.split(separator: " ").compactMap{Int($0)}
graph[uv[0]].append(uv[1])
graph[uv[1]].append(uv[0])
}
var visited: [Bool] = Array(repeating: false, count: N+1)
var dp: [[Int]] = Array(repeating: Array(repeating: 0, count: 2), count: N+1)
func find(_ x: Int) {
visited[x] = true
dp[x][0] = 1
for child in graph[x] {
if visited[child] { continue }
find(child)
dp[x][0] += min(dp[child][0], dp[child][1])
dp[x][1] += dp[child][0]
}
}
find(1)
print(min(dp[1][0], dp[1][1]))
}
main()