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
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])]) |
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
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])]) |
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
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])]) |
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
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])]) |
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
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])]) |
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
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 |
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) | |
class LCA: # Lowest Common Ancestor(最近共通祖先) | |
def __init__(self, G): | |
self.G = G # グラフの隣接リスト表現 | |
self.n = len(G) | |
self.log_n = 0 |
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) | |
class LCA: # Lowest Common Ancestor(最近共通祖先) | |
def __init__(self, G): | |
self.G = G # グラフの隣接リスト表現 | |
self.n = len(G) | |
self.log_n = 0 |
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, L = map(int, input().split()) | |
K = int(input()) | |
A = list(map(int, input().split())) | |
# 判定問題(すべての長さを x 以上にすることは可能か?) | |
def check(x): | |
num = 0 # 何個切れたか | |
pre = 0 # 前回の切れ目 | |
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
def dfs(str1, nex): | |
if len(str1) == 11: | |
ret = f(int(str1)) | |
s.add(ret) | |
return | |
for i in range(nex, 10): | |
str2 = str1 | |
str2 += str(i) | |
dfs(str2, i) | |
return |