From fa3c52bb8c74d4d664ab07d4f8e158a2448b1c07 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Fri, 22 Mar 2024 10:33:47 +0900 Subject: [PATCH] aloha graph2(1967, 3109) --- zeta_python/1967.py | 0 zeta_python/completed/1967.py | 40 +++++++++++++++++++++++++++++++ zeta_python/completed/3109.py | 45 +++++++++++++++++++++++++++++++++++ zeta_python/run.ps1 | 5 ++++ 4 files changed, 90 insertions(+) delete mode 100644 zeta_python/1967.py create mode 100644 zeta_python/completed/1967.py create mode 100644 zeta_python/completed/3109.py create mode 100644 zeta_python/run.ps1 diff --git a/zeta_python/1967.py b/zeta_python/1967.py deleted file mode 100644 index e69de29..0000000 diff --git a/zeta_python/completed/1967.py b/zeta_python/completed/1967.py new file mode 100644 index 0000000..8eed327 --- /dev/null +++ b/zeta_python/completed/1967.py @@ -0,0 +1,40 @@ +def solve(N, E): + D = [] + D.append((0, 1, 0)) + finals = [] + while D: + before, header, distance = D.pop(0) + nexts = E[header] + cnt = 0 + for s in nexts: + if s[0] != before: + D.append((header, s[0], distance + s[1])) + cnt += 1 + if cnt == 0: + finals.append((header, distance)) + + D = [] + s1 = max(finals, key=lambda x: x[1]) + D.append((0, s1[0], 0)) + finals = [] + while D: + before, header, distance = D.pop(0) + nexts = E[header] + cnt = 0 + for s in nexts: + if s[0] != before: + D.append((header, s[0], distance + s[1])) + cnt += 1 + if cnt == 0: + finals.append((header, distance)) + + return max(finals, key=lambda x: x[1])[1] + + +if __name__ == '__main__': + N: int = int(input()) + E = [[] for _ in range(N + 1)] + for a, b, v in [map(int, input().split()) for _ in range(N - 1)]: + E[a].append((b, v)) + E[b].append((a, v)) + print(solve(N, E)) diff --git a/zeta_python/completed/3109.py b/zeta_python/completed/3109.py new file mode 100644 index 0000000..44fbcd1 --- /dev/null +++ b/zeta_python/completed/3109.py @@ -0,0 +1,45 @@ +def get_maximum_upper(R, C, M, start): + now_r = start + now_c = 0 + D = [(now_r, now_c)] + dir = [(-1, 1), (0, 1), (1, 1)] + while D: + now_r, now_c = D.pop() + M[now_r][now_c] = 1 + insert = [] + for dr, dc in dir: + new_r, new_c = now_r + dr, now_c + dc + if new_c == C - 1: + if 0 <= new_r < R: + M[new_r][new_c] = 1 + return True + continue + + if 0 <= new_r < R: + if M[new_r][new_c]: + continue + insert.append((new_r, new_c)) + if insert: + D.extend(insert[::-1]) + return [] + + +def solve(R, C, M): + cnt = 0 + for i in range(R): + path = get_maximum_upper(R, C, M, i) + if path: + cnt += 1 + else: + continue + + return cnt + + +if __name__ == '__main__': + import sys + + R, C = map(int, sys.stdin.readline().split()) + M = [list(map(lambda x: 1 if x == "x" else 0, sys.stdin.readline().rstrip())) for _ in range(R)] + + print(solve(R, C, M)) diff --git a/zeta_python/run.ps1 b/zeta_python/run.ps1 new file mode 100644 index 0000000..8af1de5 --- /dev/null +++ b/zeta_python/run.ps1 @@ -0,0 +1,5 @@ +if ($args.Length -gt 0) { + type stdin.txt | python $args[0] +} else { + Write-Host "No args" +}