input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list([x-1 for x in MII()])
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _... | import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list([x-1 for x in MII()])
#======================================================#
def main():
s = IS()
cnt = len(s)
for c in set(s):
... | p03687 |
import sys
input = sys.stdin.buffer.readline
from collections import deque
N, M = list(map(int, input().split()))
abcs = [tuple(map(int, input().split())) for _ in range(N)]
defs = [tuple(map(int, input().split())) for _ in range(M)]
xs = set([0])
ys = set([0])
for a, b, c in abcs:
xs.add(a)
xs.... | import sys
input = sys.stdin.buffer.readline
N, M = list(map(int, input().split()))
abcs = [tuple(map(int, input().split())) for _ in range(N)]
defs = [tuple(map(int, input().split())) for _ in range(M)]
xs = set([0])
ys = set([0])
for a, b, c in abcs:
xs.add(a)
xs.add(b)
ys.add(c)
for d, e... | p02680 |
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque
INF = 10**20
n, m = list(map(int, input().split()))
xseen = set()
xseen.add(INF); xseen.add(-INF)
yseen = set()
yseen.add(INF); yseen.add(-INF)
a_b_c = []
for _ in range(n):
a, b, c = list(map(int, input().spli... | #!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque
INF = 10**20
n, m = list(map(int, input().split()))
xseen = set()
xseen.add(INF); xseen.add(-INF)
yseen = set()
yseen.add(INF); yseen.add(-INF)
a_b_c = []
for _ in range(n):
a, b, c = list(map(int, input().spli... | p02680 |
# F - . (Single Dot)
from collections import deque
import sys
readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
INF = 10**9 + 1
s_X = set()
s_Y = set()
s_X.add(0)
s_X.add(INF)
s_X.add(-INF)
s_Y.add(0)
s_Y.add(INF)
s_Y.add(-INF)
def compress(s):
ls = list(s)
ls.sort()
... | # F - . (Single Dot)
import bisect
import sys
readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
INF = 10**9 + 1
s_X = set([-INF, 0, INF])
s_Y = set([-INF, 0, INF])
def compress(s):
ls = list(s)
ls.sort()
return {e: i for i, e in enumerate(ls)}
ABC = []
for i in ran... | p02680 |
def main():
n,m=map(int,input().split())
def hashh(x1,y1,x2,y2):
if x1>x2:
x1,y1,x2,y2=x2,y2,x1,y1
if x1==x2 and y1>y2:
x1,y1,x2,y2=x2,y2,x1,y1
return x1*27000000000+y1*9000000+x2*3000+y2
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,i... | n,m=map(int,input().split())
def hashh(x,y,f):
return (x*3000+y)*2+f
abc_l=[list(map(int,input().split()))for _ in range(n)]
def_l=[list(map(int,input().split()))for _ in range(m)]
x=[0]
y=[0]
for a,b,c in abc_l:
x.append(a)
x.append(b)
y.append(c)
for d,e,f in def_l:
x.append(d)
y.... | p02680 |
import sys
# from itertools import chain, accumulate
n, m, *abcdef = list(map(int, sys.stdin.buffer.read().split()))
ver_lines = []
hor_lines = []
x_list = set()
y_list = set()
n3 = n * 3
for a, b, c in zip(abcdef[0:n3:3], abcdef[1:n3:3], abcdef[2:n3:3]):
y_list.add(a)
y_list.add(b)
x_list.ad... | import sys
# from itertools import chain, accumulate
n, m, *abcdef = list(map(int, sys.stdin.buffer.read().split()))
ver_lines = []
hor_lines = []
x_list = set()
y_list = set()
n3 = n * 3
for a, b, c in zip(abcdef[0:n3:3], abcdef[1:n3:3], abcdef[2:n3:3]):
y_list.add(a)
y_list.add(b)
x_list.... | p02680 |
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): r... | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): r... | p02680 |
import sys
readline = sys.stdin.readline
def compress(L):
L2 = list(set(L))
L2.sort()
C = {v : k for k, v in enumerate(L2)}
return L2, C
N, M = list(map(int, readline().split()))
INF = 10**9+7
Wp = [tuple(map(int, readline().split())) for _ in range(N)]
Hp = [tuple(map(int, readline().sp... | import sys
readline = sys.stdin.readline
def compress(L):
L2 = list(set(L))
L2.sort()
C = {v : k for k, v in enumerate(L2)}
return L2, C
N, M = list(map(int, readline().split()))
INF = 10**9+7
Wp = [tuple(map(int, readline().split())) for _ in range(N)]
Hp = [tuple(map(int, readline().sp... | p02680 |
#!/usr/bin/python3
(n, m) = list(map(int, input().split()))
xti = {}
yti = {}
xti[0] = -1
yti[0] = -1
lvs = []
for i in range(n):
(a, b, c) = list(map(int, input().split()))
yti[a] = -1
yti[b] = -1
xti[c] = -1
lvs.append((a, b, c))
lhs = []
for i in range(m):
(d, e, f... | #!/usr/bin/python3
(n, m) = list(map(int, input().split()))
xti = {}
yti = {}
xti[0] = -1
yti[0] = -1
lvs = []
for i in range(n):
(a, b, c) = list(map(int, input().split()))
yti[a] = -1
yti[b] = -1
xti[c] = -1
lvs.append((a, b, c))
lhs = []
for i in range(m):
(d, e, f... | p02680 |
N,M = list(map(int,input().split()))
ABC = [list(map(int,input().split())) for _ in [0]*N ]
DEF = [list(map(int,input().split())) for _ in [0]*M ]
X = [0]*3003
Y = [0]*3003
INF = 10**9 + 10
X[-1] = -INF
Y[-1] = -INF
X[-2] = INF
Y[-2] = INF
i = 0
j = 0
for a,b,c in ABC:
X[i] = a
X[i+1] = b
Y... | N,M = list(map(int,input().split()))
ABC = [list(map(int,input().split())) for _ in [0]*N ]
DEF = [list(map(int,input().split())) for _ in [0]*M ]
X = [0]*3003
Y = [0]*3003
INF = 10**9 + 10
X[-1] = -INF
Y[-1] = -INF
X[-2] = INF
Y[-2] = INF
i = 0
j = 0
for a,b,c in ABC:
X[i] = a
X[i+1] = b
Y... | p02680 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
m, n = list(map(int, input().split()))
horizontal, vertical = [], []
X, Y = {-INF, 0, INF}, {-INF, 0, INF}
for _ in... | import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
m, n = list(map(int, input().split()))
horizontal, vertical = [], []
X, Y = {-INF, 0, INF}, {-INF, 0, INF}
for _ in range(m):
x0, x1, y =... | p02680 |
from collections import deque
import bisect
INF = float("inf")
N,M = list(map(int,input().split()))
xtic = {0,-INF,INF}
ytic = {0,-INF,INF}
hor = []
for _ in range(N):
a,b,c = list(map(int,input().split()))
hor.append((c,a,b))
xtic.add(a)
xtic.add(b)
ytic.add(c)
ver = []
for _ in ran... | from collections import deque
import bisect
INF = float("inf")
N,M = list(map(int,input().split()))
xtic = {0,-INF,INF}
ytic = {0,-INF,INF}
hor = []
for _ in range(N):
a,b,c = list(map(int,input().split()))
hor.append((c,a,b))
xtic.add(a)
xtic.add(b)
ytic.add(c)
ver = []
for _ in ran... | p02680 |
n, m = list(map(int, input().split()))
NS = []
X_num = set()
EW = []
Y_num = set()
INF = 10 ** 36
X_num.add(INF)
X_num.add(0)
X_num.add(-INF)
Y_num.add(INF)
Y_num.add(0)
Y_num.add(-INF)
cant_inc_x = [[0] * 3300 for i in range(3300)]
cant_inc_y = [[0] * 3300 for i in range(3300)]
for i in range(n):... | n, m = list(map(int, input().split()))
NS = []
X_num = set()
EW = []
Y_num = set()
INF = 10 ** 36
X_num.add(INF)
X_num.add(0)
X_num.add(-INF)
Y_num.add(INF)
Y_num.add(0)
Y_num.add(-INF)
cant_inc_x = [[0] * 3300 for i in range(3300)]
cant_inc_y = [[0] * 3300 for i in range(3300)]
for i in range(n):... | p02680 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,m = list(map(int, input().split()))
mpX = {}
mpY = {}
rmpX = {}
rmpY = {}
lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**10, 0... | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,m = list(map(int, input().split()))
lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**10, 0, 10**10])
ix = 0
iy = 0
for i in range(n... | p02680 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,m = list(map(int, input().split()))
lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**10, 0, 10**10])
ix = 0
iy = 0
for i in range(n... | def main():
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,m = list(map(int, input().split()))
lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**... | p02680 |
#!usr/bin/env python3
import sys
import bisect
from collections import deque
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
return [LI() for i in range(n)]
M = 3*10**9+1
M2 = (M-10**9)**2
def solve():
n,m = LI()
p = LIR(n)
q = LIR(m)
fx = set([-M,0,M])
... | #!usr/bin/env python3
import sys
import bisect
from collections import deque
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
return [LI() for i in range(n)]
M = 3*10**9+1
M2 = (M-10**9)**2
def solve():
n,m = LI()
p = LIR(n)
q = LIR(m)
fx = set([-M,0,M])
... | p02680 |
#!usr/bin/env python3
import sys
import bisect
from collections import deque
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
return [LI() for i in range(n)]
M = 3*10**9+1
M2 = (M-10**9)**2
def solve():
n,m = LI()
p = LIR(n)
q = LIR(m)
fx = set([-M,0,M])
... | #!usr/bin/env python3
import sys
import bisect
from collections import deque
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
return [LI() for i in range(n)]
M = 3*10**9+1
M2 = (M-10**9)**2
n,m = LI()
p = LIR(n)
q = LIR(m)
fx = set([-M,0,M])
fy = set([-M,0,M])
for i in ran... | p02680 |
#!usr/bin/env python3
import sys
import bisect
from collections import deque
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
return [LI() for i in range(n)]
M = 3*10**9+1
M2 = (M-10**9)**2
n,m = LI()
p = LIR(n)
q = LIR(m)
fx = set([-M,0,M])
fy = set([-M,0,M])
for i in ran... | #!usr/bin/env python3
import sys
import bisect
from collections import deque
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
return [LI() for i in range(n)]
M = 3*10**9+1
M2 = (M-10**9)**2
n,m = LI()
p = LIR(n)
q = LIR(m)
fx = set([-M,0,M])
fy = set([-M,0,M])
for i in ran... | p02680 |
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return in... | import sys
from collections import deque
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI... | p02680 |
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
de... | from collections import deque
def LI():return [int(i) for i in input().split()]
ans=0
inf=1<<65
n,m=LI()
X=[0,inf,-inf]
Y=[0,inf,-inf]
V=[]
H=[]
for i in range(n):
a,b,c=LI()
V.append(((a,b),c))
Y.append(c)
X.append(a)
X.append(b)
n+=2
V.append(((-inf,inf),inf))
V.append(((-inf... | p02680 |
I=lambda:list(map(int,input().split()));F=1<<65;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(s... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(so... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(so... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(so... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(so... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(so... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y+=[c];X+=[a,b]
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X+=[a];Y+=[b,c]
s=dict(enumerate(sorted(set(X))));K=len(s);t=dict(enumerate(sorted(set(Y))));L=len(t);... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(so... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=set([0]+f);Y=set(X);R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X.add(a);Y.add(b);Y.add(c)
s=dict(enumerate(sorted(X)));K=len(s);t=dict(enumerate(so... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y+=[c];X+=[a,b]
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X+=[a];Y+=[b,c]
s=dict(enumerate(sorted(set(X))));K=len(s);t=dict(enumerate(sorted(set(Y))));L=len(t);... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y+=[c];X+=[a,b]
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X+=[a];Y+=[b,c]
def g(X):
s=dict(enumerate(sorted(set(X))));K=len(s);h={s[i]:i for i in s}
return ... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y+=[c];X+=[a,b]
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X+=[a];Y+=[b,c]
def g(X):
s=dict(enumerate(sorted(set(X))));K=len(s);h={s[i]:i for i in s}
return ... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y+=[c];X+=[a,b]
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X+=[a];Y+=[b,c]
def g(X):s=dict(enumerate(sorted(set(X))));return s,len(s),{s[i]:i for i in s}
s,K,h=... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):a,b,c=I();R+=[((a,b),c)];Y+=[c];X+=[a,b]
for i in r(m):a,b,c=I();H+=[(a,(b,c))];X+=[a];Y+=[b,c]
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=Y=[0]+f;R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=[c];X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=[a];Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)+1
h,s,K=g(X);w,t,L=g(Y);j=lamb... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=[c];X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=[a];Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)+1
h,s,K=g(X);w,t,L=g(Y);j... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=c,;X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)+1
h,s,K=g(X);w,t,L=g(Y);j=l... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=c,;X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)+1
h,s,K=g(X);w,t,L=g(Y);j=l... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);j=lambd... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);j=lambd... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);j=lambd... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);j=lambd... | p02680 |
I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=sorted(set(X));l=len(s);return{s[i]:i for i in r(l)},s,l
h,s,K=g(X);w,t,L=g(Y);V,U,v=[[[0]*-~K for... | I=lambda:list(map(int,input().split()));F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=(f,F),(f,-F),;H=(F,f),(-F,f),
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=sorted(set(X));l=len(s);return{s[i]:i for i in r(l)},s,l
h,s,K=g(X);w,t,L=g(Y);V,U,v=[[[0]*-~K for... | p02680 |
N, M = list(map(int, input().split()))
A, B, C = [], [], []
for _ in range(N):
a, b, c = list(map(int, input().split()))
A.append(a)
B.append(b)
C.append(c)
D, E, F = [], [], []
for _ in range(M):
d, e, f = list(map(int, input().split()))
D.append(d)
E.append(e)
F.append(f)
orig_X = sorte... | N, M = list(map(int, input().split()))
A, B, C = [], [], []
for _ in range(N):
a, b, c = list(map(int, input().split()))
A.append(a)
B.append(b)
C.append(c)
D, E, F = [], [], []
for _ in range(M):
d, e, f = list(map(int, input().split()))
D.append(d)
E.append(e)
F.append(f)
orig_X = sorte... | p02680 |
import sys
import operator
from itertools import repeat
from functools import partial, reduce
from typing import Iterable, Tuple, Union
Indices = Union[int, slice, Tuple[Union[int, slice]]]
class nd (list):
def at(self, position : Tuple[int]):
return reduce(operator.getitem, position, self)
def se... | import sys
import operator
from itertools import repeat
from functools import partial, reduce
from typing import Iterable, Tuple, Union
Indices = Union[int, slice, Tuple[Union[int, slice]]]
class nd (list):
def at(self, position : Tuple[int]):
return reduce(operator.getitem, position, self)
def se... | p02680 |
import sys
import operator
from itertools import repeat
from functools import partial, reduce
from typing import Iterable, Tuple, Union
Indices = Union[int, slice, Tuple[Union[int, slice]]]
class nd (list):
def at(self, position : Tuple[int]):
return reduce(operator.getitem, position, self)
def se... | import sys
import operator
from itertools import repeat
from functools import partial, reduce
from typing import Iterable, Tuple, Union
Indices = Union[int, slice, Tuple[Union[int, slice]]]
class nd (list):
def at(self, position : Tuple[int]):
return reduce(operator.getitem, position, self)
def se... | p02680 |
import sys
import operator
from itertools import repeat
from functools import partial, reduce
from typing import Any, Callable, Iterable, Tuple, Union
Indices = Union[int, slice, Tuple[Union[int, slice]]]
ndgetter = (
lambda a, i: a,
lambda a, i: a[i[0]],
lambda a, i: a[i[0]][i[1]],
lambda a, i: a[i[0... | import sys
import operator
from itertools import repeat
from functools import partial, reduce
from typing import Any, Callable, Iterable, Tuple, Union
Indices = Union[int, slice, Tuple[Union[int, slice]]]
ndgetter = (
lambda a, i: a,
lambda a, i: a[i[0]],
lambda a, i: a[i[0]][i[1]],
lambda a, i: a[i[0... | p02680 |
import sys
import operator
from itertools import repeat
from functools import partial, reduce
from typing import Any, Callable, Iterable, Tuple, Union
Indices = Union[int, slice, Tuple[Union[int, slice]]]
ndgetter = (
lambda a, i: a,
lambda a, i: a[i[0]],
lambda a, i: a[i[0]][i[1]],
lambda a, i: a[i[0... | import sys
from typing import Iterable, Tuple, Union
class nd (object):
getter = (
lambda a, i: a,
lambda a, i: a[i[0]],
lambda a, i: a[i[0]][i[1]],
lambda a, i: a[i[0]][i[1]][i[2]],
lambda a, i: a[i[0]][i[1]][i[2]][i[3]],
lambda a, i: a[i[0]][i[1]][i[2]][i[3]][i[4]],
lambda a, i: a[i[0]][i[1... | p02680 |
# -*- coding: utf-8 -*-
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def ma... | # -*- coding: utf-8 -*-
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def ma... | p02680 |
import sys
input = sys.stdin.readline
def compress(set_):
"""座標圧縮した辞書を返す"""
array2 = sorted(list(set_))
memo = {value: index for index, value in enumerate(array2)}
return memo
def calc_s(hi, wj):
"""座標圧縮後の範囲hi <= i < hi - 1, wj <= j < wj + 1について、
座標圧縮前の面積を求める
"""
res =... | import sys
input = sys.stdin.readline
def compress(set_):
"""座標圧縮した辞書を返す"""
array2 = sorted(list(set_))
memo = {value: index for index, value in enumerate(array2)}
return memo
def calc_s(hi, wj):
"""座標圧縮後の範囲hi <= i < hi - 1, wj <= j < wj + 1について、
座標圧縮前の面積を求める
"""
res =... | p02680 |
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,m = [int(i) for i in readline().split()]
yoko = [[int(i) for i in readline().split()] for _ in range(n)]
tate = [[int(i) for i in readline().split()] for _ in range(m)]
INF = 10**9+5
xcoord = [-INF,0,INF]
yc... | # coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,m = [int(i) for i in readline().split()]
tate = [[int(i) for i in readline().split()] for _ in range(n)]
yoko = [[int(i) for i in readline().split()] for _ in range(m)]
INF = 10**9+5
hcoord = {-INF,0,INF}
wc... | p02680 |
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,m = [int(i) for i in readline().split()]
tate = [[int(i) for i in readline().split()] for _ in range(n)]
yoko = [[int(i) for i in readline().split()] for _ in range(m)]
INF = 10**9+5
hcoord = {-INF,0,INF}
wc... | class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) #親ノード
self.size = [1]*n #グループの要素数
def root(self, x): #root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
... | p02680 |
class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) #親ノード
self.size = [1]*n #グループの要素数
def root(self, x): #root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
... | class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) #親ノード
self.size = [1]*n #グループの要素数
def root(self, x): #root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
... | p02680 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
class UnionFind(object):
def __init__(self, N):
self.tree = [-1]*N
def root(self, i):
if sel... | #!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, ... | p02680 |
def f_single_dot():
from collections import deque
N, M = [int(i) for i in input().split()]
x = {0} # 重複を除いた x 座標の一覧 (座標圧縮に必要)
y = {0}
vertical_lines = []
horizontal_lines = []
for _ in range(N):
a, b, c = [int(i) for i in input().split()]
vertical_lines.append((a,... | def f_single_dot():
# https://atcoder.jp/contests/abc168/submissions/13368489
import sys
from collections import deque
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
X, Y = set([0]), set([0])
A, B, C = [0] * N, [0] * N, [0] * N
for i in range(N):
A... | p02680 |
def f_single_dot():
# https://atcoder.jp/contests/abc168/submissions/13368489
import sys
from collections import deque
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
X, Y = set([0]), set([0])
A, B, C = [0] * N, [0] * N, [0] * N
for i in range(N):
A... | def f_single_dot():
# https://atcoder.jp/contests/abc168/submissions/13368489
import sys
from collections import deque
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
X, Y = set([0]), set([0])
A, B, C = [0] * N, [0] * N, [0] * N
for i in range(N):
A... | p02680 |
def f_single_dot():
# https://atcoder.jp/contests/abc168/submissions/13368489
import sys
from collections import deque
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要)
vertical_lines = []
for _ ... | def f_single_dot():
# https://atcoder.jp/contests/abc168/submissions/13368489
import sys
from collections import deque
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要)
vertical_lines = []
for _ ... | p02680 |
def f_single_dot():
# 参考: https://atcoder.jp/contests/abc168/submissions/13368489
import sys
from collections import deque
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要)
vertical_lines = []
fo... | def f_single_dot():
# 参考: https://atcoder.jp/contests/abc168/submissions/13368489
import sys
from collections import deque
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
x_set, y_set = set([0]), set([0]) # 重複を除いた xy 座標の一覧 (座標圧縮に必要)
vertical_lines = []
fo... | p02680 |
n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
distance=[9999999999999999]*n
distance[0]=0
for i in range(n-1):
for j in range(m):
if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]:
distance[l[j][1]-1]=distance[l[j][0]-1]-l[j][2]
f=[0]*n
for i in range(n):
... | n,m=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
distance=[float('inf')]*n
distance[0]=0
for i in range(n-1):
for j in range(m):
if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]:
distance[l[j][1]-1]=distance[l[j][0]-1]-l[j][2]
x=distance[n-1]
for i in range(... | p03722 |
N, M = list(map(int, input().split()))
adjacent = []
score = ['None' for i in range(N)]
score[0] = 0
for i in range(M):
a, b, c = list(map(int, input().split()))
adjacent.append([a-1, b-1, c])
for i in range(2*N):
for j in adjacent:
if score[j[1]] == 'None' and score[j[0]] != 'None':
... | N, M = list(map(int, input().split()))
adjacent = []
score = ['None' for i in range(N)]
score[0] = 0
for i in range(M):
a, b, c = list(map(int, input().split()))
adjacent.append([a-1, b-1, c])
for i in range(N):
for j in adjacent:
if score[j[1]] == 'None' and score[j[0]] != 'None':
s... | p03722 |
N, M = list(map(int, input().split()))
E = []
for _ in range(M):
a,b,c = list(map(int, input().split()))
E.append((a,b,c))
dist = [-N*10**9]*(N+1)
dist[1] = 0
flag = False
for i in range(N):
for (a,b,c) in E:
newlen = dist[a] + c
if newlen > dist[b]:
if i == N-1:
... | N, M = list(map(int, input().split()))
E = []
for _ in range(M):
a,b,c = list(map(int, input().split()))
E.append((a,b,c))
dist = [-N*10**9]*(N+1)
dist[1] = 0
flag = False
for i in range(N):
for (a,b,c) in E:
newlen = dist[a] + c
if newlen > dist[b]:
dist[b] = newlen
... | p03722 |
N, M = list(map(int, input().split()))
E = []
for i in range(M):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
c = -c
E.append([a, b, c])
dist = [float('inf')] * (N+1)
dist[0] = 0
for n in range(N):
for a, b, c in E:
if (dist[a] != float('inf')) & (dist[b] > di... | N, M = list(map(int, input().split()))
Edges = []
for i in range(M):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
c = -c
Edges.append([a, b, c])
dist = [float('inf')] * N
dist[0] = 0
for i in range(N):
for fr, to, cost in Edges:
if (dist[fr] != float('inf')) a... | p03722 |
import sys
stdin = sys.stdin
def na(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def bf(es, n, start, ved):
I = 999999999999999999
d = [I] * n
d[start] = 0
for i in range(n-1):
updated = False
for e in es:
... | import sys
stdin = sys.stdin
def na(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def bf(es, n, start, ved):
I = 999999999999999999
d = [I] * n
d[start] = 0
for i in range(n-1):
updated = False
for e in es:
... | p03722 |
def BellmanFord(edges, num_v, source):
#グラフの初期化
inf = float("inf")
dist = [inf for i in range(num_v)]
dist[source-1] = 0
#変の和
for i in range(num_v):
for edge in edges:
if dist[edge[0]-1] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
dist[e... | def BellmanFord(edges, num_v, source):
#グラフの初期化
inf = float("inf")
dist = [inf for i in range(num_v)]
dist[source-1] = 0
#辺の和
for i in range(num_v):
for edge in edges:
if dist[edge[0]-1] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
dist[e... | p03722 |
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
e = [set() for _ in range(N + 1)]
reve = [[] for _ in range(N + 1)]
for _ in range(M):
u, v, c = list(map(int, input().split()))
e[u].add((v, -c))
reve[v].append(u)
vis = [0] * (N + 1)
def revdfs(x):
global vis
if x == ... | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
e = []
for _ in range(M):
u, v, c = list(map(int, input().split()))
e.append((u, v, -c))
inf = 10 ** 18
d = [inf] * (N + 1)
d[1] = 0
for _ in range(N - 1):
for u, v, c in e: d[v] = min(d[v], d[u] + c)
loop = []
for u, v, c i... | p03722 |
n, m = list(map(int, input().split()))
graph = [tuple(map(int, input().split())) for _ in range(m)]
def shortest_path(s):
MIN = -1 * 10 ** 12
d = [MIN] * (n + 1)
d[s] = 0
update = True
cnt = 1
tmp = MIN
while update:
update = False
for a, b, c in graph:
... | n, m = list(map(int, input().split()))
graph = [tuple(map(int, input().split())) for _ in range(m)]
def shortest_path(s):
MIN = -1 * 10 ** 12
d = [MIN] * (n + 1)
d[s] = 0
update = True
cnt = 1
tmp = MIN
while update:
update = False
for a, b, c in graph:
... | p03722 |
import sys
# sys.stdin = open('d1.in')
n, m = list(map(int, input().split()))
weights = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
weights[(a, b)] = c
score = [-10 ** 50] * n
score[0] = 0
pred = [-1] * n
for i in range(n):
for edge, c in list(wei... | import sys
# sys.stdin = open('d1.in')
n, m = list(map(int, input().split()))
weights = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
a -= 1
b -= 1
weights[(a, b)] = c
score = [-10 ** 50] * n
score[0] = 0
pred = [-1] * n
for i in range(n):
for edge, c in list(wei... | p03722 |
N,M = list(map(int,input().split()))
edge = [0]*M
for i in range(M):
a,b,c=list(map(int,input().split()))
a -= 1
b -= 1
c *= -1
edge[i] = (a,b,c)
inf = float('inf')
V = N
E = M
d = [inf]*V
d[0] = 0
for i in range(V):
for j in range(E):
From,To,cost = edge[j]
if ... | N,M = list(map(int,input().split()))
edge = [0]*M
for i in range(M):
a,b,c=list(map(int,input().split()))
a -= 1
b -= 1
c *= -1
edge[i] = (a,b,c)
inf = float('inf')
V = N
E = M
d = [inf]*V
d[0] = 0
for i in range(V):
update = False
for j in range(E):
From,To,cost = ... | p03722 |
import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {i : [] for i in range(n)}
edge_ls = []
for i in range(m):
a, b, c = [int(i) for i in sys.stdin.readline().split()]
a -= 1
b -= 1
graph[a].append((b, c))
edge_ls.append((a, b, c))
INF = float("inf")
d = [-INF for i... | import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {i : [] for i in range(n)}
edge_ls = []
for i in range(m):
a, b, c = [int(i) for i in sys.stdin.readline().split()]
a -= 1
b -= 1
graph[a].append((b, c))
edge_ls.append((a, b, c))
INF = float("inf")
d = [-INF for i... | p03722 |
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutat... | import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutat... | p03722 |
#!/usr/bin/env python3
#ABC61 D
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import item... | #!/usr/bin/env python3
#ABC61 D
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import item... | p03722 |
n, m = list(map(int, input().split()))
edges = [None] * m
for i in range(m):
a, b, c = list(map(int, input().split()))
edges[i] = (a-1, b-1, -c)
INF = float("inf")
d = [INF] * n
d[0] = 0
for i in range(n-1):
for f, t, c in edges:
if d[f] == INF: continue
d[t] = min(d[t], d[f... | INF = float("inf")
def bellman_ford(edges, n, s):
d = [0] + [INF] * (n-1)
for i in range(n):
for f, t, c in edges:
if d[f] == INF: continue
if d[t] > d[f] + c:
if i == n-1: d[t] = -INF
else: d[t] = d[f] + c
for i in range(n):
... | p03722 |
import sys
N, M = list(map(int, input().split()))
graph = [0] * (M)
for m in range(M):
a, b, c = list(map(int, input().split()))
graph[m] = (a, b, -c)
INF = 1e18
distance = [INF] * N
distance[0] = 0
count = 0
while True:
count += 1
update = False
for i in range(M):
a, b... | import sys
N, M = list(map(int, input().split()))
graph = [0] * (M)
for m in range(M):
a, b, c = list(map(int, input().split()))
graph[m] = (a, b, -c)
INF = 1e18
distance = [INF] * N
distance[0] = 0
for n in range(N):
for i in range(M):
a, b, c = graph[i]
if INF != distan... | p03722 |
N, M = list(map(int,input().split()))
side = [[]for _ in range(N)]
for _ in range(M):
a,b,c = list(map(int,input().split()))
side[a-1].append([b-1,c])
node = [-float('inf')]*N
node[0] = 0
queue = [0]
nque = []
for i in range(N+5):
while queue:
q = queue.pop(-1)
for a,c in side[q]... | N, M = list(map(int,input().split()))
side = [[]for _ in range(N)]
for _ in range(M):
a,b,c = list(map(int,input().split()))
side[a-1].append([b-1,c])
node = [-float('inf')]*N
node[0] = 0
for _ in range(N):
for i in range(N):
for b,c in side[i]:
node[b] = max(node[b],node[i]+c)... | p03722 |
import sys
input = sys.stdin.readline
def bellmanford(G, s):
n = len(G)
inf = -float('inf')
dist = [inf] * n
dist[s] = 0
for i in range(2*n):
for v in range(n):
for w, c in G[v]:
if dist[w] < dist[v] + c:
dist[w] = dist[v] + c
... | import sys
input = sys.stdin.readline
def bellmanford(G, s):
n = len(G)
inf = -float('inf')
dist = [inf] * n
dist[s] = 0
for i in range(n):
for v in range(n):
for w, c in G[v]:
if dist[w] < dist[v] + c:
dist[w] = dist[v] + c
... | p03722 |
import sys
inf = float('inf')
n, m = list(map(int, sys.stdin.readline().split()))
a = []
b = []
c = []
for _ in range(m):
ai, bi, ci = list(map(int, sys.stdin.readline().split()))
a.append(ai - 1)
b.append(bi - 1)
c.append(-ci)
abc = list(zip(a, b, c))
def main():
dist = [inf] * n... | import sys
inf = float('inf')
n, m = list(map(int, sys.stdin.readline().split()))
abc = []
for _ in range(m):
a, b, c = list(map(int, sys.stdin.readline().split()))
abc.append((a-1, b-1, -c))
def main():
dist = [inf] * n
dist[0] = 0
for _ in range(n-1):
for a, b, c in abc:
... | p03722 |
from copy import deepcopy
n, m = [int(i) for i in input().split()]
es = [[int(j) for j in input().split()] for i in range(m)]
x = [float('-inf')] * (n+1)
x[1] = 0
for i in range(n):
for a, b, c in es:
x[b] = max(x[b], x[a]+c)
xcp = deepcopy(x)
prevxn = x[n]
for a, b, c in es:
x[b]... | from copy import deepcopy
n, m = [int(i) for i in input().split()]
es = [[int(j) for j in input().split()] for i in range(m)]
x = [float('-inf')] * (n+1)
x[1] = 0
for i in range(n):
for a, b, c in es:
x[b] = max(x[b], x[a]+c)
xcp = [i for i in x]
prevxn = x[n]
for a, b, c in es:
x... | p03722 |
inf = float('INF')
class edge:
def __init__(self, source, destination, weight):
self.from_ = source
self.to_ = destination
self.weight = weight
def values(self):
return self.from_, self.to_, self.weight
def bellman_ford(edges, start, n):
costs = [inf] * n
... |
def bellman_ford(edges, start, n):
inf = float('INF')
costs = [inf] * n
predecessors = [-1] * n
costs[start]= 0
for _ in range(n-1):
for e in edges:
u,v,c = e
if costs[v] > costs[u] + c:
costs[v] = costs[u] + c
predecessor... | p03722 |
#coding:utf-8
import sys
from collections import defaultdict
if __name__ == "__main__":
N, M = list(map(int, input().split(" ")))
V = set()
E = []
for i in range(M):
a, b, c = list(map(int, input().split(" ")))
V.add(a)
V.add(b)
E.append((a, b, -c))
... | #coding:utf-8
import sys
from collections import defaultdict
if __name__ == "__main__":
N, M = list(map(int, input().split(" ")))
V = set()
E = []
for i in range(M):
a, b, c = list(map(int, input().split(" ")))
V.add(a)
V.add(b)
E.append((a, b, -c))
... | p03722 |
n, m = list(map(int, input().split()))
NINF = -10**20
edge = []
dist = [NINF]*n
dist[0] = 0
for _ in range(m):
a, b, c = list(map(int, input().split()))
edge.append((a-1, b-1, c))
for i in range(2*n):
for a, b, c in edge:
if dist[a]!=NINF and dist[b] < dist[a] + c:
dist[b] = d... | n, m = list(map(int, input().split()))
NINF = -10**20
edge = []
dist = [NINF]*n
dist[0] = 0
for _ in range(m):
a, b, c = list(map(int, input().split()))
edge.append((a-1, b-1, c))
for i in range(n):
for a, b, c in edge:
if dist[a]!=NINF and dist[b] < dist[a] + c:
dist[b] = dis... | p03722 |
N,M = list(map(int, input().split()))
from collections import defaultdict
neighbor = defaultdict(list)
rev_neighbor = defaultdict(list)
E = []
for i in range(M):
a,b,c = list(map(int, input().split()))
a,b = a-1, b-1
E += [(a,b,c)]
neighbor[a].append(b)
rev_neighbor[b].append(a)
def reachable... | N,M = list(map(int, input().split()))
from collections import defaultdict
E = []
for i in range(M):
a,b,c = list(map(int, input().split()))
a,b = a-1, b-1
E += [(a,b,c)]
def reachable_vertices(neighbor, s):
V = set()
V.add(s)
stack=[s]
while stack:
v = stack.pop()
for u in neigh... | p03722 |
import sys
from collections import Counter
inf = 1<<60
def solve():
N, M = list(map(int, input().split()))
edges = [None]*M
for i in range(M):
ui, vi, ci = list(map(int, sys.stdin.readline().split()))
edges[i] = (ui-1, vi-1, -ci)
ans = Bellmanford(N, M, edges)
... | import sys
from collections import Counter
sys.setrecursionlimit(10**7)
inf = 1<<100
def solve():
N, M = list(map(int, input().split()))
edges = [None]*M
Adj = [[] for i in range(N)]
for i in range(M):
ui, vi, ci = list(map(int, sys.stdin.readline().split()))
ui, vi ... | p03722 |
import sys
from collections import Counter
sys.setrecursionlimit(10**7)
inf = 1<<100
def solve():
N, M = list(map(int, input().split()))
edges = [None]*M
Adj = [[] for i in range(N)]
for i in range(M):
ui, vi, ci = list(map(int, sys.stdin.readline().split()))
ui, vi ... | import sys
inf = 1<<60
def solve():
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
ai, bi, ci = list(map(int, sys.stdin.readline().split()))
ai, bi = ai - 1, bi - 1
edges[i] = (ai, bi, -ci)
ans = BellmanFord(N, M, edges)
if an... | p03722 |
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
N,M = inpl()
lines = defaultdict(set)... | from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
N,M = inpl()
lines = defaultdict(set)... | p03722 |
N, M = list(map(int, input().split()))
a, b, c = [0] * M, [0] * M, [0] * M
d = [-1e20] * N
for i in range(M):
a[i], b[i], c[i] = list(map(int, input().split()))
a[i] -= 1
b[i] -= 1
d[0] = 0
for i in range(N-1):
for j in range(M):
d[b[j]] = max((d[b[j]], d[a[j]] + c[j]))
isCycle = ... | N, M = list(map(int, input().split()))
a, b, c = [None] * M, [None] * M, [None] * M
INF = 1e14
d = [-INF] * N
d[0] = 0
for i in range(M):
a[i], b[i], c[i] = list(map(int, input().split()))
a[i] -= 1
b[i] -= 1
for i in range(N):
for j in range(M):
if d[a[j]] + c[j] > d[b[j]]:
... | p03722 |
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI... | import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI... | p03722 |
def main():
N, M = list(map(int, input().split()))
g = [[] for _ in range(N + 1)]
d = [float('INF')] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
c = -c
g[a].append((b, c))
for i in range(2 * N):
for x, r in enumerate(g... | def main():
N, M = list(map(int, input().split()))
g = []
d = [float('INF')] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
g.append((a, b, -c))
for i in range(2 * N):
for x, y, z in g:
if d[x] != float('INF') and d[y... | p03722 |
def main():
N, M = list(map(int, input().split()))
g = []
d = [float('INF')] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
g.append((a, b, -c))
for i in range(2 * N):
for x, y, z in g:
if d[x] != float('INF') and d[y... | def main():
N, M = list(map(int, input().split()))
g = []
INF = 10 ** 9 * 1000
d = [INF] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
g.append((a, b, -c))
for i in range(2 * N):
for x, y, z in g:
if d[x] != INF... | p03722 |
import sys
input=sys.stdin.readline #危険!基本オフにしろ!
def BELLMANFORD(point,d,n):
cost = [-float("inf")for node in range(n+1)]
cost[point]= 0
for i in range(n-1): #経路の長さは最大n-1であるため
for now,lis in list(d.items()):
for nex,c in lis:
... | import sys
input=sys.stdin.readline #危険!基本オフにしろ!
def BELLMANFORD(point,n,d):
cost=[1e18]*(n+1)
cost[point]=0
for i in range(n-1):
for (nownode,nextnode,c) in d:
if cost[nextnode]>cost[nownode]+c: #infが定数なので論理が逆
cost[nextnode]=cost[nownode]+c
for (nownod... | p03722 |
from collections import deque
n,m = list(map(int,input().split()))
e1 = [[] for i in range(n)]
e2 = [[] for i in range(n)]
l = []
for i in range(m):
a,b,c = list(map(int,input().split()))
a -= 1
b -= 1
e1[a].append(b)
e2[b].append(a)
l.append([a,b,c])
def search(x,e):
dis = [0... | from collections import deque
n,m = list(map(int,input().split()))
e1 = [[] for i in range(n)]
e2 = [[] for i in range(n)]
l = []
for i in range(m):
a,b,c = list(map(int,input().split()))
a -= 1
b -= 1
e1[a].append(b)
e2[b].append(a)
l.append([a,b,c])
def search(x,e):
dis = [0... | p03722 |
import sys
def input(): return sys.stdin.readline().strip()
N, M = (list)(list(map(int, input().split())))
edge = []
for _ in range(M):
edge.append((list)(list(map(int, input().split()))))
inf = 10**15
d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N-1):
for a, b, c in edge:
... | import sys
def input(): return sys.stdin.readline().strip()
N, M = (list)(list(map(int, input().split())))
edge = []
for _ in range(M):
edge.append((list)(list(map(int, input().split()))))
inf = 10**15
d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N-1):
for a, b, c in edge:
... | p03722 |
N,M = list(map(int,input().split()))
ABC = [list(map(int,input().split())) for _ in [0]*M]
E = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
for a,b,c in ABC:
E[a-1][b-1] = -c
Eb[b-1][a-1] = -c
#0 -> N-1 経路上にない頂点を除く
V1 = [False]*N
V1[0] = True
q = [0]
qp = q.pop
qa = q.append
while q:
i = q... | def main():
N,M = list(map(int,input().split()))
ABC = [list(map(int,input().split())) for _ in [0]*M]
E = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
for a,b,c in ABC:
E[a-1][b-1] = -c
Eb[b-1][a-1] = -c
#0 -> N-1 経路上にない頂点を除く
V1 = [False]*N
V1[0] = True
... | p03722 |
from collections import deque
N, M = list(map(int, input().split()))
edges = []
dfsEdges = [[] for _ in range(N)]
dfsReverseEdges = [[] for _ in range(N)]
for _ in range(M):
back, to, cost = list(map(int, input().split()))
back -= 1
to -= 1
edges.append((back, to, -cost))
dfsEdges[... | N, M = list(map(int, input().split()))
edges = []
E = [[] for _ in range(N)]
for _ in range(M):
fr, to, cost = list(map(int, input().split()))
fr -= 1
to -= 1
edges.append((fr, to, -cost))
E[to].append(fr)
def canGo():
st = [N - 1]
visited = [False] * N
visited[N - 1] = T... | p03722 |
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
G = [[-float('inf')] * N for _ in range(N)]
score = [-float('inf')] * N
score[0] = 0
passed = [False] * N
for m in range(M):
a, b, c = [int(x) for x in input().strip().split()]
G[a-1][b-1] = c
updated = [False] ... | import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
score = [-float('inf')] * N
score[0] = 0
passed = [False] * N
edges = [0] * M
for m in range(M):
edges[m] = tuple([int(x) for x in input().strip().split()])
for n in range(N):
updated = False
for (i, j, c) in... | p03722 |
def bell(edges, n):
count = 0
dist = [-10000000000000000 for i in range(n)]
dist[0] = 0
changed = True
while changed:
count += 1
if count == 500000:
print('inf')
exit()
changed = False
for edge in edges:
if dist[edg... | N, M = list(map(int, input().split()))
Edges = []
for i in range(M):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
c = -c
Edges.append([a, b, c])
dist = [float('inf')] * N
dist[0] = 0
for i in range(N):
for fr, to, cost in Edges:
if (dist[fr] != float('inf'))... | p03722 |
N, M = list(map(int, input().split()))
Edges = []
for i in range(M):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
c = -c
Edges.append([a, b, c])
dist = [float('inf')] * N
dist[0] = 0
for i in range(N):
for fr, to, cost in Edges:
if (dist[fr] != float('inf'))... | def bell(edges, n):
count = 0
dist = [float('inf') for i in range(n)]
dist[0] = 0
for i in range(n):
for edge in edges:
if dist[edge[1]] > dist[edge[0]] + edge[2] and edge[0] != float('inf'):
dist[edge[1]] = dist[edge[0]] + edge[2]
if (i =... | p03722 |
class BellmanFord:
def __init__(self, graph, num_v, start_point):
self.num_v = num_v
self.graph = graph
self.start_point = start_point
def execute(self):
dist = [float("inf") for _ in range(self.num_v)]
dist[self.start_point] = 0
negative = [False for ... | class BellmanFord:
def __init__(self, graph, num_v, start_point):
self.num_v = num_v
self.graph = graph
self.start_point = start_point
def execute(self):
dist = [float("inf") for _ in range(self.num_v)]
dist[self.start_point] = 0
negative = [False for ... | p03722 |
N,M = list(map(int,input().split()))
from collections import deque
ls = [deque([]) for _ in range(N)]
for i in range(M):
a,b,c = list(map(int,input().split()))
a,b = a-1,b-1
ls[a].append([b,c])
cost = [-(10**10)*N]*N
cost[0] = 0
for i in range(N):
update = False
q = [deque(m for m i... | N,M = list(map(int,input().split()))
abc = []
for _ in range(M):
abc.append(list(map(int,input().split())))
cost = [-(10**10)*N]*N
cost[0] = 0
for i in range(N):
update = False
for a,b,c in abc:
a,b = a-1,b-1
if cost[a] != -(10**10)*N:
if cost[b] < cost[a] + c:
... | p03722 |
N,M = list(map(int,input().split()))
abc = []
for _ in range(M):
abc.append(list(map(int,input().split())))
cost = [-float('inf')]*N
cost[0] = 0
for i in range(N):
update = False
for a,b,c in abc:
a,b = a-1,b-1
if cost[a] != -(10**10)*N:
if cost[b] < cost[a] + c:
... | N,M = list(map(int,input().split()))
abc = []
for _ in range(M):
abc.append(list(map(int,input().split())))
cost = [-float('inf')]*N
cost[0] = 0
for i in range(2):
for a,b,c in abc:
a,b = a-1,b-1
cost[b] = max(cost[b], cost[a] + c)
if i == 0:
ans = cost[N-1]
els... | p03722 |
from collections import defaultdict
N, M, *L = list(map(int, open(0).read().split()))
dic = defaultdict(list)
rdic = defaultdict(list)
nin = [0]*N
Els = []
for a,b,c in zip(*[iter(L)]*3):
dic[a-1] += [b-1]
rdic[b-1] += [a-1]
nin[b-1] += 1
Els += [(a-1,b-1,-c)]
To = [False]*N
From = [False]*N
q = ... | from collections import defaultdict
N, M, *L = list(map(int, open(0).read().split()))
dic = defaultdict(list)
rdic = defaultdict(list)
nin = [0]*N
Els = []
for a,b,c in zip(*[iter(L)]*3):
dic[a-1] += [b-1]
rdic[b-1] += [a-1]
nin[b-1] += 1
Els += [(a-1,b-1,-c)]
To = [False]*N
From = [False]*N
q = ... | p03722 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from ma... | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from ma... | p03722 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from ma... | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from ma... | p03722 |
#### import ####
import sys
import math
from collections import defaultdict
#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
#### 定数 ####
mod = 10**9 + 7
#### 読み込み ####
def I(): return int(eval(input()))
def II(): return list(map(int, input().split()))
def III... | #### import ####
import sys
import math
from collections import defaultdict
#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
#### 定数 ####
mod = 10**9 + 7
#### 読み込み ####
def I(): return int(eval(input()))
def II(): return list(map(int, input().split()))
def III... | p03722 |
n,m=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]
loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
item,depth=q.pop()
if depth<=len(s):
for _ in range(len(s)-de... | n,m=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]
dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15
for _ in range(n):
for p in range(n):
for i,j in g[p]:
dist[i]=max(dist... | p03722 |
ai = lambda: list(map(int, input().split()))
n, m = ai()
from collections import defaultdict as dd
edge = dd(list)
for _ in range(m):
a, b, c = ai()
edge[a - 1].append([b - 1, -c])
dist = [float('inf')] * n
dist[0] = 0
vs = {0}
i = 0
while vs:
cur_v = vs.pop()
for v, c in edge[cur_v... | ai = lambda: list(map(int, input().split()))
n, m = ai()
from collections import defaultdict as dd
edge = dd(list)
for _ in range(m):
a, b, c = ai()
edge[a - 1].append([b - 1, -c])
dist = [float('inf')] * n
dist[0] = 0
vs = {0}
i = 0
while vs:
cur_v = vs.pop()
for v, c in edge[cur... | p03722 |
inf = float('inf')
n, m = list(map(int, input().split()))
e = []
for _ in range(m):
s, t, c = list(map(int, input().split()))
s -= 1
t -= 1
c *= -1
e.append((s, t, c))
dist = [inf] * n
dist[0] = 0
ans = None
for cnt in range(n * 2):
for s, t, c in e:
if dist[s] != inf... | def Bellman_Ford(s, g, inf=1 << 60):
# https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html
N = len(g)
dist = [inf] * N
dist[s] = 0
for _ in range(N):
not_updated = True
for v in range(N):
for u, c in g[v]:
if (dist[v] == inf... | p03722 |
# -*- coding: utf-8 -*-
"""
・ベルマンフォード
"""
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M):
a, b, c = list(map(int, input().split()))
# 0-indexed
# コストの正負を逆転させれば最短経路問題として... | # -*- coding: utf-8 -*-
"""
参考:https://img.atcoder.jp/abc061/editorial.pdf
・ベルマンフォード
・負の閉路があっても、そこに頂点Nが含まれなければ今回はOK
って点に気付けなかったー。
"""
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
N, M = list(map(int, input().split()))
edges = [None] * M
for i in range(M... | p03722 |
import sys
N, M = list(map(int, input().split()))
a_list = list()
b_list = list()
c_list = list()
for _ in range(M):
a, b, c = list(map(int, input().split()))
a_list.append(a)
b_list.append(b)
c_list.append(-c)
inf = sys.maxsize
dist = [inf for _ in range(N)]
dist[0] = 0
for _ in r... | import sys
N, M = list(map(int, input().split()))
a_list = list()
b_list = list()
c_list = list()
for _ in range(M):
a, b, c = list(map(int, input().split()))
a_list.append(a)
b_list.append(b)
c_list.append(-c)
inf = sys.maxsize
dist = [inf] * N
dist[0] = 0
for loop in range(N):
... | p03722 |
# -*- coding: utf-8 -*-
inf = 10**50
n,m = list(map(int, input().split()))
ea = []
eb = []
cost = []
for _ in range(m):
a,b,c = list(map(int, input().split()))
a -= 1
b -= 1
ea.append(a)
eb.append(b)
cost.append(-c)
d = [inf for _ in range(n)]
d[0] = 0
for _ in range(n):
... | # -*- coding: utf-8 -*-
inf = 10**50
n,m = list(map(int, input().split()))
ea = []
eb = []
cost = []
for _ in range(m):
a,b,c = list(map(int, input().split()))
a -= 1
b -= 1
ea.append(a)
eb.append(b)
cost.append(-c)
d = [inf for _ in range(n)]
d[0] = 0
for _ in range(n):
... | p03722 |
# -*- coding: utf-8 -*-
import sys
from collections import deque
N,M=list(map(int, sys.stdin.readline().split()))
#edge=[ map(int, sys.stdin.readline().split()) for _ in range(M) ] #辺
al=[ [] for _ in range(N+1) ] #隣接リスト
rev_al=[ [] for _ in range(N+1) ] #戻りを調べる用の隣接リスト
edge=[] #辺の集合
for _ in range(M):
... | # -*- coding: utf-8 -*-
import sys
from collections import deque
N,M=list(map(int, sys.stdin.readline().split()))
al=[ [] for _ in range(N+1) ] #隣接リスト
rev_al=[ [] for _ in range(N+1) ] #戻りを調べる用の隣接リスト
edge=[] #辺の集合
for _ in range(M):
a,b,c=list(map(int, sys.stdin.readline().split()))
al[a].append(... | p03722 |
import sys
stdin = sys.stdin
def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): re... | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.re... | p03722 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.