This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
def distance(): | |
N = 5 # ノードの個数 | |
INF = float("inf") # 十分大きい定数 | |
# edge[m, n]には、ノードmからノードnへの距離を格納 | |
# 二つのノードが隣接していない場合には INF を格納 | |
edge = [ | |
[INF, 10, 16, INF, INF], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def distance(): | |
N = 5 # ノードの個数 | |
INF = float("inf") # 十分大きい定数 | |
# edge[m, n]には、ノードmからノードnへの距離を格納 | |
# 二つのノードが隣接していない場合には INF を格納 | |
edge = [ | |
[INF, 10, 16, INF, INF], | |
[10, INF, 4, 3, INF], | |
[16, 4, INF, 2, 3], | |
[INF, 3, 2, INF, 6], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def distance(): | |
N = 5 # ノードの個数 | |
INF = float("inf") # 十分大きい定数 | |
# edge[m, n]には、ノードmからノードnへの距離を格納 | |
# 二つのノードが隣接していない場合には INF を格納 | |
edge = [ | |
[INF, 10, 16, INF, INF], | |
[10, INF, 4, 3, INF], | |
[16, 4, INF, 2, 3], | |
[INF, 3, 2, INF, 6], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
input = sys.stdin.readline | |
N, M, Q = map(int, input().split()) | |
G = [[] for _ in range(N)] | |
for _ in range(M): | |
x, y = map(lambda n: int(n) - 1, input().split()) | |
G[y].append(x) # 子が親へのポインタを持つようなグラフ | |
ans = [] | |
for i in range(N): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MLEになるバージョン | |
import sys | |
sys.setrecursionlimit(10**7) | |
input = sys.stdin.readline | |
def dfs(n): | |
if (dp[n] >> n) & 1: | |
return dp[n] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
A = list(map(int, input().split())) | |
s = sum(A) | |
dp = 1 | |
for i in range(N): | |
dp |= dp << A[i] | |
ans = (s + 1) // 2 | |
while ans <= 2000 * 2000 + 1: | |
if (dp >> ans) & 1: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INF = 10**10 | |
N, M = map(int, input().split()) | |
A = list(map(int, input().split())) | |
dp = [INF] * N # dp[i]:町iの上流をたどって見たとき、金1kgを買える最安値 | |
G = [[] for _ in range(N)] | |
for _ in range(M): | |
x, y = map(lambda n: int(n) - 1, input().split()) | |
G[x].append(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.setrecursionlimit(10**7) | |
dir = [(1, 0), (0, 1), (-1, 0), (0, -1)] | |
MOD = 10**9 + 7 | |
def dfs(x, y): | |
if dp[y][x] != 0: | |
return dp[y][x] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for g in range(12): | |
s = set() | |
i = 0 | |
while True: | |
v = (g * i) % 12 | |
if v in s: | |
break | |
s.add(v) | |
i += 1 | |
print(f"<{g:>2}> = {s}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.setrecursionlimit(10**7) | |
def dfs(v): | |
if dp[v] != -1: # 調査済み | |
return dp[v] | |
ret = 0 | |
for nxt in G[v]: |
NewerOlder