diff --git a/zeta_python/completed/1167.py b/zeta_python/completed/1167.py new file mode 100644 index 0000000..18021ea --- /dev/null +++ b/zeta_python/completed/1167.py @@ -0,0 +1,47 @@ +import sys + +input = sys.stdin.readline + + +def longest(E, start) -> tuple[int, int]: + D = [] + + M = 0 + V_M = 0 + D.append((start, [start], 0)) # now, visited, accumulated + + while D: + now, visited, accumulated = D.pop(0) + flag = True + for e in E[now]: + target, cost = e[0], e[1] + if target not in visited: + flag = False + D.append((target, visited + [target], cost + accumulated)) + + if flag: + if accumulated > M: + M = accumulated + V_M = now + + return V_M, M + + +def solve(V, E): + first = longest(E, 1)[0] + _, diameter = longest(E, first) + + return diameter + + +if __name__ == "__main__": + V = int(input()) + E = {} + for _ in range(V): + _i = list(map(int, input().split())) + E[_i[0]] = [] + + for i, v in zip(_i[1:-1:2], _i[2:-1:2]): + E[_i[0]].append((i, v)) + + print(solve(V, E)) diff --git a/zeta_python/completed/1629.py b/zeta_python/completed/1629.py new file mode 100644 index 0000000..e132529 --- /dev/null +++ b/zeta_python/completed/1629.py @@ -0,0 +1,17 @@ +def solve(A, B, C) -> int: + A %= C + ret = 1 + while B: + if B % 2 == 1: + ret *= A + ret %= C + A *= A + A %= C + B //= 2 + + return ret + + +if __name__ == "__main__": + A, B, C = map(int, input().split()) + print(solve(A, B, C))