boj step 9 rework & aloha graph1(16174,2606,1520)

This commit is contained in:
2024-03-19 15:48:39 +09:00
parent 3745a83e2a
commit 636b945497
8 changed files with 173 additions and 0 deletions

0
zeta_python/1967.py Normal file
View File

View File

@@ -0,0 +1,4 @@
a, b = map(int, input().split())
print(a // b)
print(a % b)

View File

@@ -0,0 +1,32 @@
import sys
sys.setrecursionlimit(1 << 16)
def solve(M, N, U):
"""get count of pathes"""
Mem = [[-1 for _ in range(N)] for _ in range(M)]
Mem[M - 1][N - 1] = 1
def dfs(now):
x, y = now
if Mem[x][y] != -1:
return Mem[x][y]
cnt = 0
for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
_x, _y = x + i, y + j
if 0 <= _x < M and 0 <= _y < N and U[_x][_y] < U[x][y]:
cnt += dfs((_x, _y))
Mem[x][y] = cnt
return Mem[x][y]
dfs((0, 0))
return Mem[0][0]
if __name__ == '__main__':
M, N = map(int, input().split())
U = [list(map(int, input().split())) for _ in range(M)] # U[m][n]
print(solve(M, N, U))

View File

@@ -0,0 +1,33 @@
def solve(N, A) -> bool:
now = (0, 0)
D = []
D.append(now)
X = [[0 for _ in range(N)]for _ in range(N)]
while D:
now = D.pop()
amount = A[now[0]][now[1]]
if X[now[0]][now[1]]:
continue
X[now[0]][now[1]] = 1
if amount == 0:
continue
elif amount == -1:
return True
if now[0] + amount >= N:
pass
else:
target = (now[0] + amount, now[1])
D.append(target)
if now[1] + amount >= N:
pass
else:
target = (now[0], now[1] + amount)
D.append(target)
return False
if __name__ == '__main__':
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
print("HaruHaru" if solve(N, A) else "Hing")

View File

@@ -0,0 +1,30 @@
def solve(N, X, E):
ComputerMap = {}
WormMap = [0 for i in range(N + 1)]
WormMap[1] = 1
for i in range(1, N + 1):
ComputerMap[i] = []
for e in E:
ComputerMap[e[0]].append(e[1])
ComputerMap[e[1]].append(e[0])
D = []
D.append(1)
while D:
x = D.pop()
connected = ComputerMap[x]
for conn in connected:
if WormMap[conn]:
continue
else:
WormMap[conn] = 1
D.append(conn)
return sum(WormMap) - 1
if __name__ == '__main__':
N = int(input())
X = int(input())
E = list(sorted(list(map(int, input().split()))) for _ in range(X))
print(solve(N, X, E))