Skip to content

Instantly share code, notes, and snippets.

class RollingHash:
def __init__(self, str, base, mod):
self.base = base
self.mod = mod
self.pow = [1] * (len(str) + 1)
self.hash = [0] * (len(str) + 1)
for i in range(len(str)):
self.hash[i + 1] = (self.hash[i] * base + ord(str[i])) % mod
self.pow[i + 1] = self.pow[i] * base % mod
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
from collections import deque
class Dinic:
def __init__(self, max_v):
self.n = max_v
self.G = [[] for _ in range(self.n)]
def add_edge(self, fr, to, cap): # frからtoへ向かう容量capの辺を追加する
self.G[fr].append([to, cap, len(self.G[to])])
from atcoder.maxflow import MFGraph
def index(i, j):
return i * M + j
N, M = map(int, input().split())
S = [list(input()) for _ in range(N)]
g = MFGraph(N * M + 2)
from collections import deque
class Dinic:
def __init__(self, max_v):
self.n = max_v
self.G = [[] for _ in range(self.n)]
def add_edge(self, fr, to, cap): # frからtoへ向かう容量capの辺を追加する
self.G[fr].append([to, cap, len(self.G[to])])
from collections import deque
class Dinic:
def __init__(self, max_v):
self.n = max_v
self.G = [[] for _ in range(self.n)]
def add_edge(self, fr, to, cap): # frからtoへ向かう容量capの辺を追加する
self.G[fr].append([to, cap, len(self.G[to])])
from collections import deque
class Dinic:
def __init__(self, max_v):
self.n = max_v
self.G = [[] for _ in range(self.n)]
def add_edge(self, fr, to, cap): # frからtoへ向かう容量capの辺を追加する
self.G[fr].append([to, cap, len(self.G[to])])
from collections import deque
class Dinic:
def __init__(self, max_v):
self.n = max_v
self.G = [[] for _ in range(self.n)]
def add_edge(self, fr, to, cap): # frからtoへ向かう容量capの辺を追加する
self.G[fr].append([to, cap, len(self.G[to])])
@maehrm
maehrm / math_risan15_q.py
Last active March 3, 2024 07:54
うさぎでもわかる離散数学(グラフ理論) 第15羽 最大フロー・最小カットの求め方 | 工業大学生ももやまのうさぎ塾 https://www.momoyama-usagi.com/entry/math-risan15#i-7
from collections import deque
class Dinic:
def __init__(self, max_v):
self.n = max_v
self.G = [[] for _ in range(self.n)]
def add_edge(self, fr, to, cap): # frからtoへ向かう容量capの辺を追加する
self.G[fr].append([to, cap, len(self.G[to])])
@maehrm
maehrm / math_risan15_q.py
Last active March 2, 2024 09:10
うさぎでもわかる離散数学(グラフ理論) 第15羽 最大フロー・最小カットの求め方 | 工業大学生ももやまのうさぎ塾 https://www.momoyama-usagi.com/entry/math-risan15#i-7
from atcoder.maxflow import MFGraph
N = 7 # Node数(駅の数)
M = 12 # Edge数(路線の数)
g = MFGraph(N)
g.add_edge(0, 1, 12) # (0)渋谷 -> (1)新宿 12
g.add_edge(0, 2, 25) # (0)渋谷 -> (2)表参道 25
g.add_edge(2, 1, 3) # (2)表参道 -> (1)新宿 3