input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
#coding:UTF-8 import copy n = list(map(int,input().split())) if n[0]<n[1]<n[2]: print("Yes") else: print("No")
#coding:UTF-8 n = list(map(int,input().split())) if n[0]<n[1]<n[2]: print("Yes") else: print("No")
p02392
nums = input().split() a = int(nums[0]) b = int(nums[1]) c = int(nums[2]) if a < b < c: print('Yes') else: print('No')
a, b, c = list(map(int, input().split())) if a < b < c: print("Yes") else: print("No")
p02392
import sys if __name__ == '__main__': import doctest doctest.testmod() a, b, c = list(map(int, sys.stdin.read().split())) if a < b < c: print("Yes") else: print("No")
#!/usr/bin/env python #-*- coding: utf-8 -*- # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_B if __name__ == '__main__': a, b, c = list(map(int, input().split())) if a < b < c: print("Yes") else: print("No")
p02392
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 import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
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 import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
p02666
def par(a): L = [] while P[a] != a: L.append(a) a = P[a] for l in L: P[l] = a return a def unite(a, b): pa = par(a) pb = par(b) if pa == pb: return if LEN[pa] < LEN[pb]: a, b, pa, pb = b, a, pb, pa P[pb] = pa if LEN[pa] == LEN[pb]: L...
def par(a): L = [] while P[a] != a: L.append(a) a = P[a] for l in L: P[l] = a return a def unite(a, b): pa = par(a) pb = par(b) if pa == pb: return if LEN[pa] < LEN[pb]: a, b, pa, pb = b, a, pb, pa P[pb] = pa if LEN[pa] == LEN[pb]: L...
p02666
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") MOD = 1000000007 # type: int class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: ...
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") MOD = 1000000007 # type: int class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: ...
p02666
# AGC002B - Box and Ball def main(): N, M = tuple(map(int, input().split())) X = tuple(tuple(map(int, input().split())) for _ in range(M)) R = [0] * (N + 1) # red ball may be in box i R[1] = 1 C = [1] * (N + 1) # number of balls in box i (count) for x, y in X: if R[x]: ...
# AGC002B - Box and Ball import sys input = sys.stdin.readline def main(): N, M = tuple(map(int, input().split())) X = tuple(tuple(map(int, input().split())) for _ in range(M)) R = [0] * (N + 1) # red ball may be in box i R[1] = 1 C = [1] * (N + 1) # number of balls in box i (count) ...
p04034
from sys import stdin def main(): #入力 readline=stdin.readline N,M=list(map(int,readline().split())) x=[0]*M y=[0]*M for i in range(M): a,b=list(map(int,readline().split())) x[i]=a y[i]=b li=[[1,0] for _ in range(N+1)] li[1][1]=1 for i in range(M...
from sys import stdin def main(): #入力 readline=stdin.readline N,M=list(map(int,readline().split())) x=[0]*M y=[0]*M for i in range(M): x[i],y[i]=list(map(int,readline().split())) box=[1]*(N+1) flags=[False]*(N+1) flags[1]=True for i in range(M): o...
p04034
def main(): n, m = input_list() box = [False]*n box[0] = True nums = [1]*n for i in range(m): x, y = input_list() if box[x-1]: box[y-1] = True nums[x-1] = nums[x-1] - 1 nums[y-1] = nums[y-1] + 1 if nums[x-1] == 0: box[x-1] = False print((box.count(True))) ...
# import sys # input = sys.stdin.readline import itertools # 持っているビスケットを叩き、1枚増やす # ビスケット A枚を 1円に交換する # 1円をビスケット B枚に交換する def main(): n, m = input_list() balls = [1] * n reds = [False] * n reds[0] = True for _ in range(m): x, y = input_list() if reds[x-1]: ...
p04034
#!/usr/bin/env python3 (n, m), *q = [[*list(map(int, i.split()))] for i in open(0)] b = [1] + [0] * (n - 1) c = [1] * n for x, y in q: c[x - 1] -= 1 c[y - 1] += 1 b[y - 1] |= b[x - 1] b[x - 1] *= c[x - 1] > 0 print((sum(b)))
(n, m), *q = [[*list(map(int, i.split()))] for i in open(0)] b = [0] * (n + 1) b[1] = 1 c = [1] * (n + 1) for x, y in q: c[x] -= 1 c[y] += 1 b[y] |= b[x] b[x] *= c[x] > 0 print((sum(b)))
p04034
n, m = list(map(int, input().split())) moves = [list(map(int, input().split())) for i in range(m)] possibilities = [False] * n possibilities[0] = True nums = [1] * n for i in range(m): x = moves[i][0] - 1 y = moves[i][1] - 1 if possibilities[x]: possibilities[y] = True nums[x...
n, m = list(map(int, input().split())) moves = [list(map(int, input().split())) for i in range(m)] possibilities = [False] * n possibilities[0] = True nums = [1] * n for i in range(m): x = moves[i][0] - 1 y = moves[i][1] - 1 if possibilities[x]: possibilities[y] = True nums[x...
p04034
n,m=list(map(int,input().split())) cnt=[1]*n s=set([1]) for i in range(m): x,y=list(map(int,input().split())) cnt[y-1]+=1 cnt[x-1]-=1 if x in s: s.add(y) if cnt[x-1]==0: if x in s: s.remove(x) print((len(s)))
n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(m)] count=[1]*(n+1) s=set() s.add(1) for a,b in arr: count[b]+=1 count[a]-=1 if a in s: s.add(b) if count[a]==0: s.discard(a) print((len(s)))
p04034
n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(m)] count=[1]*(n+1) s=set() s.add(1) for a,b in arr: count[b]+=1 count[a]-=1 if a in s: s.add(b) if count[a]==0: s.discard(a) print((len(s)))
n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(m)] count=[1]*(n+1) flag=[False]*(n+1) flag[1]=True for a,b in arr: count[b]+=1 count[a]-=1 if flag[a]==True: flag[b]=True if count[a]==0: flag[a]=False print((flag.count(True)))
p04034
n,m=list(map(int,input().split())) cnt=[1]*n res=[0]*n res[0]=1 for i in range(m): x,y=list(map(int,input().split())) if res[x-1]==1: res[y-1]=1 if cnt[x-1]==1: res[x-1]=0 cnt[x-1]-=1 cnt[y-1]+=1 print((sum(res)))
def main(): n,m=list(map(int,input().split())) cnt=[1]*n res=[0]*n res[0]=1 for i in range(m): x,y=list(map(int,input().split())) if res[x-1]==1: res[y-1]=1 if cnt[x-1]==1: res[x-1]=0 cnt[x-1]-=1 cnt[y-1]+=1 pri...
p04034
n,m=list(map(int,input().split())) x=[0]*n x[0]=1 y=[1]*n for i in range(m): a,b=list(map(int,input().split())) if x[a-1]==1:x[b-1]=1 y[a-1]-=1 y[b-1]+=1 if y[a-1]==0:x[a-1]=0 print((sum(x)))
n,m=list(map(int,input().split())) ans=[False]*n ans[0]=True co=[1]*n for i in range(m): x,y=list(map(int,input().split())) ans[y-1]|=ans[x-1] co[x-1]-=1 co[y-1]+=1 if co[x-1]==0:ans[x-1]=False print((ans.count(True)))
p04034
N, M = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(M)] red = [0] * (N+1) #赤になりうる場所を1とする red[1] = 1 red[0] = "" ball = [1] * (N+1) #個数 ball[0] = "" for x, y in xy: ball[y] += 1 ball[x] -= 1 if red[x] == 1: red[y] = 1 if ball[x] == 0: red[x] = 0 print((r...
n,m = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(m)] box = [1]*(n+1) red = [0]*(n+1) red[1] = 1 for x,y in xy: box[x] -= 1 box[y] += 1 if red[x] == 1: red[y] = 1 if box[x] == 0: red[x] = 0 print((red.count(1)))
p04034
n,m = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(m)] box = [1]*(n+1) red = [0]*(n+1) red[1] = 1 for x,y in xy: box[x] -= 1 box[y] += 1 if red[x] == 1: red[y] = 1 if box[x] == 0: red[x] = 0 print((red.count(1)))
n,m = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(m)] box = [1]*(n+1) red = [0]*(n+1) red[1] = 1 for x,y in xy: box[x] -= 1 box[y] += 1 if red[x]==1: red[y] = 1 if box[x]==0: red[x] = 0 print((sum(red)))
p04034
n,m = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(m)] box = [1] * (n+1) red = [0] * (n+1) red[1] = 1 for x,y in xy: box[x] -= 1 box[y] += 1 if red[x] == 1: red[y] = 1 if box[x] == 0: red[x] = 0 print((red.count(1)))
n,m = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(m)] red = [0] * (n+1) red[1] = 1 ball = [1] * (n+1) for x,y in xy: ball[x] -= 1 ball[y] += 1 if red[x] == 1: red[y] = 1 if ball[x] == 0: red[x] = 0 print((sum(red)))
p04034
def myAnswer(N:int,M:int,X:list,Y:list) -> int: red = 0 ans = {0} box = [1] * N for x,y in zip(X,Y): if(x-1 in ans): ans.add(y-1) box[x-1] -= 1 box[y-1] += 1 for i in list(ans): if(box[i] == 0): ans.remove(i) return len(ans) def modelAn...
''' Accepted  :No difficult  : ペナルティ   :5分 実際の回答時間 :分 WAの回数  :回 合計時間    :分 ''' def myAnswer(N:int,M:int,X:list,Y:list) -> int: ans = {0} box = [1] * N for x,y in zip(X,Y): if(x-1 in ans): if(box[x - 1]==1): ans.remove(x-1) ans.add(y-1) bo...
p04034
N, M = list(map(int, input().split())) b = [1] * N b[0] = -1 for i in range(M): x, y = list(map(int, input().split())) if b[x - 1] < 0: b[x - 1] += 1 b[y - 1] = -(abs(b[y - 1]) + 1) else: b[x - 1] -= 1 if b[y - 1] < 0: b[y - 1] -= 1 else: b[y - 1] += 1 print((len([x...
N, M = list(map(int, input().split())) b = [1] * N b[0] = -1 for i in range(M): x, y = list(map(int, input().split())) if b[x - 1] < 0: b[x - 1] += 1 if b[y - 1] >= 0: b[y - 1] = -(b[y - 1] + 1) else: b[y - 1] -= 1 else: b[x - 1] -= 1 ...
p04034
n, m = (int(x) for x in input().split()) ab = [] for _ in range(m): a, b = (int(x) for x in input().split()) ab.append([a-1, b-1]) box = [1]*n red = [0]*n red[0] = 1 for x,y in ab: if 0 < red[x]: red[y] = 1 box[x] -= 1 box[y] += 1 if box[x] == 0: red[x] = ...
N,M = list(map(int,input().split())) XY = [list(map(int,input().split())) for _ in range(M)] ball_count = [1]*N red_ball_cand = [0]*N red_ball_cand[0] = 1 for i in range(M): x,y = XY[i] x,y = x-1,y-1 if 0 < red_ball_cand[x]: red_ball_cand[y] = 1 ball_count[x] -= 1 ...
p04034
n,m = list(map(int, input().split())) d = dict() for i in range(1,n+1): d[str(i)] = 1 from collections import deque ans = deque('1') for _ in range(m): x,y = input().split() d[x] -= 1 d[y] += 1 if x in ans and y not in ans: ans.append(y) if d[x] == 0 and x in ans: ...
n,m = list(map(int, input().split())) ''' d = dict() for i in range(1,n+1): d[str(i)] = 1 from collections import deque ans = deque('1')''' box = [1 for i in range(n)] ans = [0 for i in range(n)] ans[0] = 1 for _ in range(m): x,y = list(map(int,input().split())) box[x-1] -= 1 box[y-1] += ...
p04034
N,M = list(map(int,input().split())) dp = [1 for i in range(N)] trace = [0 for i in range(N)] trace[0] = 1 for i in range(M): x,y = list(map(int,input().split())) dp[y-1] += 1 dp[x-1] -= 1 if trace[x-1] >= 1: trace[y-1] = max(trace[y-1]+1,0) if dp[x-1] == 0: trace[x-1] = 0...
N,M = list(map(int,input().split())) dp = [1 for i in range(N)] trace = [0 for i in range(N)] trace[0] = 1 for i in range(M): x,y = list(map(int,input().split())) dp[y-1] += 1 dp[x-1] -= 1 if trace[x-1] >= 1: trace[y-1] = trace[x-1] if dp[x-1] == 0: trace[x-1] = 0 print...
p04034
N,M = list(map(int, input().split())) ans = set([0]) cnt = [1] * N for _ in range(M): x,y = [int(i) - 1 for i in input().split()] cnt[x] -= 1 cnt[y] += 1 if x in ans: if cnt[x] == 0: ans.remove(x) ans.add(y) print((len(ans)))
N,M = list(map(int, input().split())) ans = set([0]) cnt = [1] * N for _ in range(M): x,y = [int(i) - 1 for i in input().split()] cnt[x] -= 1; cnt[y] += 1 if x in ans: ans.add(y) if cnt[x] == 0: # 絶対に赤いボールがyに移される ans.remove(x) print((len(ans)))
p04034
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline()...
#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [lis...
p04034
N, M = list(map(int, input().split())) A = [1 for k in range(N)] B = [0 for k in range(N)] ans = 0 B[0] = 1 for k in range(M): x, y = list(map(int, input().split())) x -= 1 y -= 1 if B[x] == 1 and A[x] >= 2: A[x] -= 1 A[y] += 1 B[y] = 1 elif B[x] == 1 and A[x] ...
N, M = list(map(int,input().split())) B = [list(map(int,input().split())) for k in range(M)] H = [1]*N E = [0]*N E[0] = 1 for e in B: x, y = e[0]-1, e[1]-1 if E[x] == 1: if H[x] == 1: E[x] = 0 E[y] = 1 else: E[y] = 1 H[x] -= 1 H[y] += 1 ...
p04034
# coding: utf-8 # Your code here!s = input() n, m = list(map(int, input().split())) x = [] y = [] for i in range(m): xi, yi = list(map(int, input().split())) x.append(xi) y.append(yi) boxes = [False]*n boxes[0] = True boxescnt = [1]*n for i in range(m): if boxes[x[i]-1] == True: if...
n, m = list(map(int, input().split())) x = [] y = [] for i in range(m): xi, yi = list(map(int, input().split())) x.append(xi) y.append(yi) num = [1]*n able = [False]*n able[0] = True for i in range(m): if able[x[i]-1] == True: able[y[i]-1] = True num[x[i]-1] -= 1 num[y[i]-1...
p04034
import sys stdin = sys.stdin sys.setrecursionlimit(10**8) 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...
import sys stdin = sys.stdin sys.setrecursionlimit(10 ** 7) 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.r...
p04034
N,M = list(map(int,input().split())) R = [0 for _ in range(N+1)] R[1] = 1 B = [1 for _ in range(N+1)] B[0] = 0 for _ in range(M): x,y = list(map(int,input().split())) if R[x]==1: R[y] = 1 B[x] -= 1 B[y] += 1 if B[x]==0: R[x] = 0 print((sum(R)))
N,M = list(map(int,input().split())) A = [0 for _ in range(N+1)] B = [1 for _ in range(N+1)] A[1] = 1 B[0] = 0 for _ in range(M): x,y = list(map(int,input().split())) if A[x]==1: A[y]=1 B[y] += 1 B[x] -= 1 if B[x]==0: A[x] = 0 print((sum(A)))
p04034
N,M = list(map(int,input().split())) A = [0 for _ in range(N+1)] B = [1 for _ in range(N+1)] A[1] = 1 B[0] = 0 for _ in range(M): x,y = list(map(int,input().split())) if A[x]==1: A[y]=1 B[y] += 1 B[x] -= 1 if B[x]==0: A[x] = 0 print((sum(A)))
N,M = list(map(int,input().split())) C = {i:[1,0] for i in range(1,N+1)} C[1] = [1,1] for _ in range(M): x,y = list(map(int,input().split())) C[y][0] += 1 if C[x][1]==1: C[y][1] = 1 C[x][0] -= 1 if C[x][0]==0: C[x][1]=0 cnt = 0 for i in range(1,N+1): if C[i][1]==1: ...
p04034
N,M = list(map(int,input().split())) C = {i:[1,0] for i in range(1,N+1)} C[1] = [1,1] for _ in range(M): x,y = list(map(int,input().split())) C[y][0] += 1 if C[x][1]==1: C[y][1] = 1 C[x][0] -= 1 if C[x][0]==0: C[x][1]=0 cnt = 0 for i in range(1,N+1): if C[i][1]==1: ...
N,M = list(map(int,input().split())) C = {i:[1,0] for i in range(1,N+1)} C[1][1] = 1 for _ in range(M): x,y = list(map(int,input().split())) C[x][0] -= 1 C[y][0] += 1 if C[x][1]==1: C[y][1]=1 if C[x][0]==0: C[x][1]=0 cnt = 0 for i in range(1,N+1): cnt += C[i]...
p04034
N, M = list(map(int,input().split())) z = [list(map(int,input().split())) for i in range(M)] box = [[1,1]] for i in range(N-1): box.append([0,1]) for i in range(M): box[z[i][0]-1][1] -= 1 box[z[i][1]-1][1] += 1 if (box[z[i][0]-1][0] == 1): box[z[i][1]-1][0] = 1 if (box[z[i][0]-1][1] == 0): ...
N, M = list(map(int, input().split())) Z = [list(map(int,input().split())) for i in range(M)] kosuu = [1 for _ in range(N)] red = [False for _ in range(N)] red[0] = True for i in range(M): x = Z[i][0] - 1 y = Z[i][1] - 1 if (kosuu[x] != 0 and red[x] == True): red[y] = True if (kosuu[x] == 1 and ...
p04034
n,m = list(map(int,input().split())) lst = [1]*n red_lst = [0] for i in range(m): x,y = list(map(int,input().split())) x -= 1 y -= 1 if (x in red_lst) and (y not in red_lst): red_lst.append(y) if lst[x]==1 and x in red_lst: red_lst.remove(x) lst[x] -= 1 lst[y] +...
n,m = list(map(int,input().split())) lst = [1]*n red_lst = [False]*n red_lst[0] = True xx = [] yy = [] for _ in range(m): a,b = list(map(int,input().split())) xx.append(a-1) yy.append(b-1) for i in range(m): x,y = xx[i], yy[i] if red_lst[x]==True and red_lst[y]==False: red_l...
p04034
def solve(): ans = 0 N, M = list(map(int, input().split())) lis = [1]*N lis[0] = -1 #赤が入っている可能性があればマイナス for _ in range(M): x,y = list(map(int, input().split())) x -= 1 y -= 1 if lis[x]<0: lis[y] = -(abs(lis[y])+1) lis[x] += 1 ...
def solve(): N, M = list(map(int, input().split())) lis = [False]*N cnt = [1]*N lis[0] = True for i in range(M): x,y = list(map(int, input().split())) x -= 1 y -= 1 if lis[x]==True: lis[y]=True if cnt[x]==1: lis[x]=False cnt[x] -= 1 cnt[y] += 1 ans ...
p04034
from collections import defaultdict n,m=list(map(int, input().split())) v = [0]*n v[0]=1 ans = [1]*n fi = 1 for i in range(m): a,b=list(map(int, input().split())) ans[a-1]-=1 ans[b-1]+=1 if v[a-1]: v[b-1]=1 fi+=1 if ans[a-1]==0: v[a-1]=0 fi-=1 print(...
n,m=list(map(int, input().split())) aka = [0]*(n+1) siroaka = [1]*(n+1) aka[1] = 1 for i in range(m): x,y=list(map(int, input().split())) siroaka[x]-=1 siroaka[y]+=1 if(aka[x]): aka[y]=1 if(siroaka[x]==0): aka[x]=0 print((sum(aka)))
p04034
i=lambda:list(map(int,input().split()));n,m=i();l=[0,1]+[0]*n;c=[0]+[1]*n for _ in[0]*m:x,y=i();l[y]|=l[x];c[y]+=1;c[x]-=1;l[x]=c[x]and l[x] print((sum(c[i]and l[i]for i in range(n+1))))
i=lambda:list(map(int,input().split()));n,m=i();a=[0]+[1]*n;b=[0,1]+[0]*n for _ in[0]*m:x,y=i();a[x]-=1;a[y]+=1;b[y]|=b[x];b[x]&=a[x]>0 print((sum(b)))
p04034
n,m=list(map(int,input().split())) a=[1]*(n+1) b=[0]*(n+1) b[1]=1 for _ in range(m): x,y=list(map(int,input().split())) a[x]-=1 a[y]+=1 if b[x]:b[y]=1 if a[x]==0:b[x]=0 ans=0 for i,j in zip(a,b): ans+=(i!=0)*j print(ans)
n,m=list(map(int,input().split())) a=[1]*(n+1) b=[0]*(n+1) b[1]=1 for _ in range(m): x,y=list(map(int,input().split())) a[x]-=1 a[y]+=1 if b[x]:b[y]=1 if a[x]==0:b[x]=0 print((sum(b)))
p04034
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) N, M = inpl() move = [inpl() for _ in range(M)] ans = [0 for _ in range(N)] ans[0] = 1 box = [1 for _ in range(N)] # print(ans, box) for i in range(M): x, y = move[i] box[x - 1] -= 1 box[y - 1] += 1 ...
# coding:utf-8 INF = float('inf') def inpl(): return list(map(int, input().split())) N, M = inpl() # move = [inpl() for _ in range(M)] ans = [0 for _ in range(N)] ans[0] = 1 box = [1 for _ in range(N)] # print(ans, box) for i in range(M): # x, y = move[i] x, y = inpl() box[x - 1] -= ...
p04034
N,M = list(map(int,input().split())) red_possible = [1] + [0]*(N-1) balls = [1] * N for i in range(M): x,y = [int(x)-1 for x in input().split()] if red_possible[x]: red_possible[y] = 1 if balls[x] == 1: red_possible[x] = 0 balls[x] -= 1 balls[y] += 1 print((sum(red...
N,M = list(map(int,input().split())) src = [tuple(map(int,input().split())) for i in range(M)] red = [0] * N red[0] = 1 ballnum = [1] * N for a,b in src: a,b = a-1,b-1 ballnum[b] += 1 ballnum[a] -= 1 if red[a]: red[b] = 1 if not ballnum[a]: red[a] = 0 print((su...
p04034
N,M = list(map(int,input().split())) XY = [tuple(map(int,input().split())) for i in range(M)] rs = [0] * N rs[0] = 1 cs = [1] * N for x,y in XY: x,y = x-1,y-1 if rs[x]: if cs[x]==1: rs[x] = 0 rs[y] = 1 cs[x] -= 1 cs[y] += 1 print((sum(rs)))
N,M = list(map(int,input().split())) XY = [tuple(map(int,input().split())) for i in range(M)] may_red = [0] * N may_red[0] = 1 balls = [1] * N for x,y in XY: x,y = x-1,y-1 if may_red[x]: may_red[y] = 1 if balls[x] == 1: may_red[x] = 0 balls[x] -= 1 balls[y] +=...
p04034
N, M = list(map(int, input().split())) y_if = {1} num = [1] * N for i in range(M): x, y = list(map(int, input().split())) num[x - 1] -= 1 num[y - 1] += 1 if x in y_if: if num[x - 1] == 0: y_if.remove(x) y_if.add(y) print((len(y_if)))
N, M = list(map(int, input().split())) ball = [1] * N red = {1} ans = 0 for _ in range(M): x, y = list(map(int, input().split())) ball[x - 1] -= 1 ball[y - 1] += 1 if x in red: red.add(y) if ball[x - 1] == 0: red.remove(x) print((len(red)))
p04034
N, M = list(map(int, input().split())) boxes = [1] * N ans = {1} for i in range(M): x, y = list(map(int, input().split())) boxes[x - 1] -= 1 boxes[y - 1] += 1 if x in ans: if boxes[x - 1] == 0: ans.remove(x) ans.add(y) print((len(ans)))
def int_(num_str): return int(num_str) - 1 N, M = list(map(int, input().split())) balls = [1] * N red = {0} for i in range(M): x, y = list(map(int_, input().split())) if x in red: if balls[x] == 1: red.remove(x) red.add(y) else: red.add(y) ...
p04034
n, m = list(map(int, input().split())) B = [1] * n R = [0] * n R[0] = 1 for _ in range(m): x, y = list(map(int, input().split())) x -= 1; y -= 1 if B[x] == 1 and R[x] == 1: R[x] = 0; R[y] = 1 elif B[x] > 1 and R[x] == 1: R[y] = 1 B[x] -= 1; B[y] += 1 print((len([...
n, m = list(map(int, input().split())) red = [False] * n ball = [1] * n red[0] = True for _ in range(m): x, y = [int(x) - 1 for x in input().split()] if red[x]: red[y] = True if ball[x] == 1: red[x] = False ball[y] += 1 ball[x] -= 1 print((len(list([x for x in...
p04034
N,M = list(map(int,input().split())) L = list(list(map(int,input().split())) for i in range(M)) A = [1 for i in range(N+1)] red = [0 for i in range(N+1)] red[1] = 1 ans = 1 for i in range(M) : A[L[i][0]] -= 1 A[L[i][1]] += 1 if red[L[i][0]] == 1 : red[L[i][1]] = 1 if A[L[i][0]] ...
N,M = list(map(int,input().split())) L = [1 for i in range(N)] R = [0 for i in range(N)] R[0] = 1 for i in range(M) : x,y = list(map(int,input().split())) x -= 1 y -= 1 L[x] -= 1 L[y] += 1 if R[x] == 1 and R[y] == 0 : R[y] = 1 if L[x] == 0 and R[x]...
p04034
(N, M), *AB = [list(map(int, s.split())) for s in open(0)] cnt = [1] * N possibly_red = [False] * N possibly_red[0] = True for a, b in AB: a -= 1 b -= 1 cnt[a] -= 1 cnt[b] += 1 if possibly_red[a]: possibly_red[b] = True if cnt[a] == 0: possibly_red[a] = False ...
N, M, *xy = list(map(int, open(0).read().split())) boxes = [{"count": 1, "red": False} for _ in range(N)] boxes[0]["red"] = True for x, y in zip(*[iter(xy)] * 2): x -= 1 y -= 1 if boxes[x]["red"]: boxes[y]["red"] = True if boxes[x]["count"] == 1: boxes[x]["red"] = Fals...
p04034
#!/usr/bin/env python3 N, M = list(map(int, input().split())) xy_table = [] for _ in range(M): x, y = list(map(int, input().split())) xy_table.append((x, y)) red_box_list = [1] # 添字0はダミー # 添字 = 箱の番号として扱う n_box_list = [0] + [1] * N for xy in xy_table: x, y = xy n_box_list[x] -= 1 ...
#!/usr/bin/env python3 N, M = list(map(int, input().split())) xy_table = [] for _ in range(M): x, y = list(map(int, input().split())) xy_table.append((x, y)) red_box_dict = {i: False for i in range(1, N + 1)} red_box_dict[1] = True # 添字0はダミー # 添字 = 箱の番号として扱う n_box_list = [0] + [1] * N for xy ...
p04034
N, M = list(map(int, input().split())) B = [[1, 0] for i in range(N)] B[0][1] = 1 for i in range(M): x, y = list(map(int, input().split())) if B[x - 1][1] == 1: B[y - 1][1] = 1 B[x - 1][0] -= 1 B[y - 1][0] += 1 if B[x - 1][0] == 0: B[x - 1][1] = 0 cnt = 0 for i in...
N, M = list(map(int, input().split())) B = [1]*N R=[0]*N R[0]=1 for i in range(M): x, y = list(map(int, input().split())) x-=1 y-=1 if R[x] == 1: R[y] = 1 B[x] -= 1 B[y] += 1 if B[x] == 0: R[x] = 0 print((sum(R)))
p04034
#!/usr/bin/env python3 def main(): N, M = list(map(int, input().split())) xy = [list(map(int, input().split())) for i in range(M)] box = [1] * N red_flag = [0] * N red_flag[0] = 1 ans = 0 for i in range(M): if red_flag[xy[i][0] - 1] == 1: red_flag[xy[i][1] - 1...
#!/usr/bin/env python3 def main(): N, M = list(map(int, input().split())) xy = [list(map(int, input().split())) for i in range(M)] box = [1] * N red_flag = [0] * N red_flag[0] = 1 ans = 0 for i in range(M): if red_flag[xy[i][0] - 1] == 1: red_flag[xy[i][1] - 1...
p04034
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N, M = list(map(int, input().split())) quantity = [1] * N red = [True] + [False] * (N - 1) for i in range(M): x, y = list(map(int, input().split())) quantit...
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): N,M=list(map(int,input().split())) X, Y = [0] * M, [0] * M for i in range(M): X[i], Y[i] = list(map(int, input().split())) red=[True]+[False]*(N-1) cnt=[1]*N f...
p04034
n, m = list(map(int, input().split())) white = [1]*n white[0] = 0 red = [0] * n red[0] = 1 for _ in range(m): x, y = list(map(int, input().split())) x -= 1 y -= 1 if red[x] > 0: red[y] += 1 else: white[y] += 1 if white[x] > 0: white[x] -= 1 else: ...
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N, M = list(map(int, input().split())) red = [0] * (N + 1) white = [1] * (N + 1) red[1] = 1 white[1] = 0 for _ in range(M): x, y = list(map(int, input().split())) if red[x]: red[y] += 1 else: white[y...
p04034
""" author : halo2halo date : 18,Oct,2019 """ import sys readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) S = readline().rstrip() ans = 'Yes' for i in range(len(S)): if i % 2 == 0 and S[i] == 'L': ans = 'No' break elif i % 2 == 1 and ...
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) S = readline().decode('utf8').rstrip() flag1 = True flag2 = True Sodd = S[::2] Seven = S[1::2] if Sodd.c...
p02910
from heapq import heappush, heappop from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time import random def I(): return int(input()) def MI(): return map(int,input().split()) ...
from heapq import heappush, heappop from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time import random def I(): return int(input()) def MI(): return map(int,input().split()) ...
p02910
def f(s): p = True for u in s: if u not in ('RUD' if p else 'LUD'): return False p ^= True return True print('Yes' if f(input()) else 'No')
def f(s): p = True for u in s: if u == ('L' if p else 'R'): return False p ^= True return True print('Yes' if f(input()) else 'No')
p02910
import queue, sys INF = 10**9+7 n = eval(input()) p = [] for i in range(n): p.append(int(input())) dist = [10**7] * n calc = [-1] * n used = [False] * n que = queue.PriorityQueue() que.put((0, 0)) dist[0] = 0 while not que.empty(): co, v = que.get() if dist[v] < co: continue for ...
import queue INF = 10**9 n = eval(input()) p = [i+int(input()) for i in range(n)] used = [0] * n idx = 0 for i in range(n): if p[i]!=i: path = [] go = i idx += 1 while go!=INF and p[go]!=go: if used[go]==idx: go = INF break ...
p01449
n = int(eval(input())) k = int(eval(input())) outcome = 1 for i in range(n): outcome = min(outcome*2, outcome+k) print(outcome)
n = int(eval(input())) k = int(eval(input())) ans = 1 for _ in range(n): ans = min(ans+k,2*ans) print(ans)
p03564
n = int(eval(input())) k = int(eval(input())) cur = 1 for i in range(n): if (cur * 2) > (cur + k): cur += k else: cur *= 2 print(cur)
n = int(eval(input())) k = int(eval(input())) res = 1 for i in range(n): if res > k: res += k else: res *= 2 print(res)
p03564
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def ...
import sys def I(): return int(sys.stdin.readline().rstrip()) N,K = I(),I() print((min(2**i+K*(N-i) for i in range(N+1))))
p03564
n = int(eval(input())) k = int(eval(input())) ans = 10**10 for i in range(2**n): m = 1 for j in range(n): if (i>>j)&1 == 1: m *= 2 else: m += k ans = min(m,ans) print(ans)
n = int(eval(input())) k = int(eval(input())) ans = 1 for i in range(n): ans = min(2*ans,ans+k) print(ans)
p03564
N = int(eval(input())) K = int(eval(input())) ans = None for i in range(2 ** N): tmp = 1 for j in range(N): if ((i >> j) &1): tmp += K else: tmp *= 2 if ans == None: ans = tmp else: ans = min(ans, tmp) print (ans)
import itertools N = int(eval(input())) K = int(eval(input())) ans = 10 ** 18 for i in itertools.product('AB', repeat = N): tmp = 1 for j in i: if j == 'A': tmp *= 2 else: tmp += K # print (i, tmp) ans = min(ans, tmp) print (ans)
p03564
n = int(eval(input())) k = int(eval(input())) a = [1] for i in range(n): if a[i] < k: a[i] = 2*a[i] a.append(a[i]) else: a[i] = a[i] + k a.append(a[i]) print((a[n-1]))
n = int(eval(input())) k = int(eval(input())) s = 1 for i in range(n): s = min(s+k,s*2) print(s)
p03564
N,K=int(eval(input())),int(eval(input())) ans=10**10 for i in range(2**N): tmp=1 for j in range(N): if (i>>(N-j-1)&1)==1: tmp*=2 else: tmp+=K ans=min(ans,tmp) print(ans)
N,K=int(eval(input())),int(eval(input())) M=[0]*(N+1) M[0]=1 for i in range(1,N+1): M[i]=min(M[i-1]*2,M[i-1]+K) print((M[N]))
p03564
n = int(eval(input())) k = int(eval(input())) i = 1 while i < k: i *= 2 n -= 1 while n != 0: i += k n -= 1 print(i)
n = int(eval(input())) k = int(eval(input())) num = 1 for i in range(n): if num + k < num * 2: num += k else: num *= 2 print(num)
p03564
N = int(eval(input())) K = int(eval(input())) ans = 10**18 for state in range(1 << N): now = 1 for d in range(N): if (state & (1 << d)) == 0: now *= 2 else: now += K ans = min(ans, now) print(ans)
N = int(eval(input())) K = int(eval(input())) ans = 1 for _ in range(N): if ans < K: ans *= 2 else: ans += K print(ans)
p03564
N=int(eval(input())) K=int(eval(input())) n=1 for i in range(N): if n<K: n*=2 else: n+=K print(n)
def solve(): n = int(eval(input())) k = int(eval(input())) ans = 1 for i in range(n): if ans < k: ans *= 2 else: ans += k print(ans) if __name__ == "__main__": solve()
p03564
n = int(eval(input())) k = int(eval(input())) res = 1 for i in range(n): if res * 2 - res < k: res *= 2 else: res += k print(res)
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) k = int(eval(input())) res = 1 for _ in range(n): if res < k: res *= 2 else: res += k prin...
p03564
N = int(eval(input())) K = int(eval(input())) min_m = 10 ** 10 for i in range(2 ** N): m = 1 for n in range(N): if i & (1 << n): m *= 2 else: m += K min_m = min(min_m, m) print(min_m)
N = int(eval(input())) K = int(eval(input())) # min_m = 10 ** 10 # for i in range(2 ** N): # m = 1 # for n in range(N): # if i & (1 << n): # m *= 2 # else: # m += K # min_m = min(min_m, m) m = 1 for i in range(N): m = min(m * 2, m + K) print(m)...
p03564
N = int(eval(input())) K = int(eval(input())) sum = 1 for i in range(N): if sum*2 <= sum+K: sum *= 2 else: sum += K print(sum)
n=int(eval(input())) k=int(eval(input())) ans=1 for i in range(n): ans=min(ans*2,ans+k) print(ans)
p03564
N=int(eval(input())) K=int(eval(input())) ans=float('inf') for i in range(2**N): bi=list(format(i,'b').zfill(N)) now=1 for b in bi: if b=='0': now*=2 else: now+=K if now<ans: ans=now print(ans)
N=int(eval(input())) K=int(eval(input())) ans=1 for i in range(N): ans=min(ans*2,ans+K) print(ans)
p03564
n=int(eval(input())) k=int(eval(input())) s=1 for i in range(n):s=min(s*2,s+k) print(s)
N=int(eval(input())) K=int(eval(input())) display=1 for i in range(N): display=min(display*2,display+K) print(display)
p03564
num = 1 n = int(eval(input())) k = int(eval(input())) for i in range(n): if num < k: num = num*2 else: num += k print(num)
n = int(eval(input())) k = int(eval(input())) start = 1 for i in range(n): start = min(start*2,start+k) print(start)
p03564
a = int(eval(input())) b = int(eval(input())) i = 0 p= 1 while i < a: if p > b: p = p+b i = i+1 else: p = 2*p i = i+1 print(p)
a = int(eval(input())) b = int(eval(input())) ans = 1 for i in range(a): ans = min(ans * 2,ans + b) print(ans)
p03564
n = int(eval(input())) k = int(eval(input())) val = 1 for i in range(n): val = min(val + k, val * 2) print(val)
n = int(eval(input())) k = int(eval(input())) p = 1 for _ in range(n): if p * 2 < p + k: p *= 2 else: p += k print(p)
p03564
#!/usr/bin/env python3 N = int(eval(input())) K = int(eval(input())) num = 1 for i in range(N): if num <= K: num *= 2 else: num += K print(num)
N=int(eval(input())) K=int(eval(input())) count=1 for i in range(N): if(count*2<count+K): count*=2 else: count+=K print(count)
p03564
n = int(eval(input())) k = int(eval(input())) val = 1 for i in range(n): if val > k: val += k else: val *= 2 print(val)
x = int(input()) y = int(input()) d = 1 for i in range(0, x): if y > d: d += d else: d += y print(d)
p03564
N = int(eval(input())) K = int(eval(input())) ans = 1 for i in range(N): if(ans*2 < ans+K): ans *= 2 else: ans += K print(ans)
N = int(eval(input())) K = int(eval(input())) ans = 1 for i in range(N): ans = min(ans*2, ans+K) print(ans)
p03564
ans=1 n=int(eval(input())) k=int(eval(input())) for i in range(n): ans=min(ans+k,ans*2) print(ans)
n=int(eval(input())) k=int(eval(input())) ans=1 for i in range(n): if k>ans: ans*=2 else : ans+=k print(ans)
p03564
N = int(eval(input())) K = int(eval(input())) ans = float('inf') for i in range(2**N): now = 1 for j in range(N): if i>>j & 1: now *= 2 else: now += K ans = min(ans, now) print(ans)
N = int(eval(input())) K = int(eval(input())) now = 1 for i in range(N): now = min(now*2, now+K) print(now)
p03564
n = int(eval(input())) k = int(eval(input())) ans = 1 for i in range(n): if ans*2 < ans + k: ans *= 2 else: ans += k print(ans)
n = int(eval(input())) k = int(eval(input())) ans = 1 for i in range(n): ans = min(ans*2, ans + k) print(ans)
p03564
s = input() p = "ABC" used = set() while s != p: idx = 0 c = [0]*3 while idx < len(s): if idx+3 <= len(s) and s[idx:idx+3] == p: idx += 3 else: c[p.index(s[idx])] += 1 idx += 1 if sum(e == 0 for e in c) != 1 or sum(c) == s: print...
s = input() p = "ABC" used = set() while s != p: idx = 0 c = [0]*3 while idx < len(s): if idx+3 <= len(s) and s[idx:idx+3] == p: idx += 3 else: c[p.index(s[idx])] += 1 idx += 1 if sum(e == 0 for e in c) != 1 or sum(c) == len(s): ...
p01811
#!/usr/bin/python if __name__ == "__main__": S = input() c = ['A','B','C'] while True: if S == "ABC": print("Yes") break T = S.strip().split("ABC") P = ''.join(T) cnt = 0 for x in c: if x in P: cnt += 1 else: S = x.join(T) if cnt != 2: print("No") ...
#!/usr/bin/python if __name__ == "__main__": S = input() c = ['A','B','C'] while True: if len(S) <= 3: print("Yes" if S == "ABC" else "No") break T = S.strip().split("ABC") if len(T) == 1: print("No") break P = ''.join(T) cnt = 0 for x in c: if x in P: cnt...
p01811
#!/usr/bin/python if __name__ == "__main__": S = input() c = ['A','B','C'] while True: if len(S) <= 3: print("Yes" if S == "ABC" else "No") break T = S.strip().split("ABC") if len(T) == 1: print("No") break P = ''.join(T) cnt = 0 for x in c: if x in P: cnt...
#!/usr/bin/python if __name__ == "__main__": S = input() c = ['A','B','C'] while True: if len(S) <= 3: print("Yes" if S == "ABC" else "No") break T = S.strip().split("ABC") P = ''.join(T) cnt = 0 for x in c: if x in P: cnt += 1 else: S = x.join(T) i...
p01811
# 同じインデックスの重複を除くので、関数の呼び出し回数が少し少ないはず。 # ただ、重複を除く分のオーバーヘッドがあるので、 # fmm, fmo, fooが軽い関数だと、スピードはそこまで出ない。 MOD = 998244353 mask = (1 << 32) - 1 mask20 = (1 << 20) - 1 mask40 = (1 << 40) - 1 class LazySegmentTree: __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self...
# 同じインデックスの重複を除くので、関数の呼び出し回数が少し少ないはず。 # ただ、重複を除く分のオーバーヘッドがあるので、 # fmm, fmo, fooが軽い関数だと、スピードはそこまで出ない。 class LazySegmentTree: __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator...
p02569
# 入力チェックオフ class LazySegmentTree: __slots__ = ["n", "original_size", "log", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, length_or_list, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator): self.me = monoid_identity ...
# 入力チェックオフ class LazySegmentTree: __slots__ = ["n", "original_size", "log", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, length_or_list, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator): self.me = monoid_identity ...
p02569
# 入力チェックオフ class LazySegmentTree: __slots__ = ["n", "original_size", "log", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, length_or_list, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator): self.me = monoid_identity ...
# 入力チェックオフ class LazySegmentTree: __slots__ = ["n", "original_size", "log", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, length_or_list, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator): self.me = monoid_identity ...
p02569
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log ...
class LazySegmentTree(): def __init__(self, n, op, e, mapping, composition, id): self.n = n self.op = op self.e = e self.mapping = mapping self.composition = composition self.id = id self.log = (n - 1).bit_length() self.size = 1 << self.log ...
p02569
#-------最強ライブラリLazy Segtree(Python)------ #Please don't say you are lazy wwwwwwww #だって Python なら TLE wwwwwwwww class lazy_segtree: # 区間更新をする遅延評価セグメント木 def __init__(s, S, op, e, F, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size...
#-------最強ライブラリLazy Segtree(Python)------ #動作確認 class lazy_segtree: #遅延評価セグメント木 def __init__(s, S, op, e, F, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size = 1 << s.log s.d = [e()] * (2 * s.size) s.lz = [id()] * s.siz...
p02569
#-------最強ライブラリLazy Segtree(Python)------ #動作確認 class lazy_segtree: #遅延評価セグメント木 def __init__(s, S, op, e, F, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size = 1 << s.log s.d = [e()] * (2 * s.size) s.lz = [id()] * s.siz...
#-------最強ライブラリLazy Segtree(Python)ver25252------ #未使用関数修正・確認 class lazy_segtree: #遅延評価セグメント木 def __init__(s, S, op, e, F, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size = 1 << s.log s.d = [e()] * (2 * s.size) s.lz = ...
p02569
class lazy_segtree: #遅延評価セグメント木 def __init__(s, op, e, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size = 1 << s.log s.d = [e()] * (2 * s.size) s.lz = [id()] * s.size s.e = e s.op = op s.mapping = mapping ...
class lazy_segtree: #遅延評価セグメント木 def __init__(s, op, e, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size = 1 << s.log s.d = [e()] * (2 * s.size) s.lz = [id()] * s.size s.e = e s.op = op s.mapping = mapping ...
p02569
class lazy_segtree: #遅延評価セグメント木 def __init__(s, op, e, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size = 1 << s.log s.d = [e()] * (2 * s.size) s.lz = [id()] * s.size s.e = e s.op = op s.mapping = mapping ...
class lazy_segtree: #遅延評価セグメント木 def __init__(s, op, e, mapping, composition, id, v): if type(v) is int: v = [e()] * v s._n = len(v) s.log = s.ceil_pow2(s._n) s.size = 1 << s.log s.d = [e()] * (2 * s.size) s.lz = [id()] * s.size s.e = e s.op = op s.mapping = mapping ...
p02569
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") ### 遅延評価セグメント木 class LazySegmentTree: def __init__(self, n, a=None): """初期化 num : n以上の最小の2のべき乗 """ num = 1 while num<=...
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") ### 遅延評価セグメント木 class LazySegmentTree: def __init__(self, n, a=None): """初期化 num : n以上の最小の2のべき乗 """ num = 1 v = 0 ...
p02569
import sys input = lambda: sys.stdin.readline().rstrip() class LazySegmentTree(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f...
import sys input = lambda: sys.stdin.readline().rstrip() class LazySegmentTree(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f...
p02569
import sys input = lambda: sys.stdin.readline().rstrip() class LazySegmentTree(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f...
import sys input = lambda: sys.stdin.readline().rstrip() class LazySegmentTree(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f...
p02569
import sys input = lambda: sys.stdin.readline().rstrip() class LazySegmentTree(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f...
import sys input = lambda: sys.stdin.readline().rstrip() class LazySegmentTree(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f...
p02569
import sys readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) N,H,W = list(map(int,readline().split())) RCA = [tuple(int(x) for x in line.split()) for line in readlines()] RCA.sort(key = lambda x: -x[2]) RCA root = list(range(H+W)) size = [0] * (H+W) no_cycle ...
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N,H,W = list(map(int,readline().split())) RCA = [tuple(int(x) for x in line.split()) for line in readlines()] RCA.sort(key = lambda x: -x[2]) RCA root = list(range(H+W)) size = [0] * (H...
p02931
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N,H,W = list(map(int,readline().split())) RCA = [tuple(int(x) for x in line.split()) for line in readlines()] RCA.sort(key = lambda x: -x[2]) RCA root = list(range(H+W)) size = [0] * (H...
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) import operator N,H,W = list(map(int,readline().split())) RCA = [tuple(int(x) for x in line.split()) for line in readlines()] RCA.sort(key = operator.itemgetter(2), reverse=True) root = li...
p02931
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) def par(a): if P[a] == a: return a t = par(P[a]) P[a] = t return t def unite(a, b): if par(a) != par(b): C[par(a)] += C[par(b)] P[par(b)] = par(a) N, H, W = list(map(int, input().split())) P = [i for i in range(H+...
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) def par(a): if P[a] < 0: return a t = par(P[a]) P[a] = t return t def unite(a, b): if par(a) == par(b): return 0 C[par(a)], C[par(b)] = C[par(a)] + C[par(b)], C[par(a)] + C[par(b)] if P[par(b)] == P[par(a)]: ...
p02931
n = int(eval(input())) list_V = list(map(int, input().split())) list_Vx = [] list_Vy = [] for i, s in enumerate(list_V): if i % 2 == 0: list_Vx.append(s) else: list_Vy.append(s) list_Vx_Count = [0 for _ in range(pow(10, 5))] list_Vy_Count = [0 for _ in range(pow(10, 5))] for i...
from collections import Counter n = int(eval(input())) list_A = list(map(int, input().split())) L, R = [], [] for i in range(n): if i % 2 == 0: L.append(list_A[i]) else: R.append(list_A[i]) A = Counter(L) A = sorted(list(A.items()), key=lambda x:x[1], reverse=True) A.append((-1,...
p03244
import collections N = int(eval(input())) even = collections.defaultdict(lambda: 0) odd = collections.defaultdict(lambda: 0) for i, a in enumerate(map(int, input().split())): if i % 2 == 0: even[a] += 1 else: odd[a] += 1 if len(list(even.keys())) == 1 and len(list(odd.keys())) =...
import collections N = int(eval(input())) even = collections.defaultdict(lambda: 0) odd = collections.defaultdict(lambda: 0) for i, a in enumerate(map(int, input().split())): if i % 2 == 0: even[a] += 1 else: odd[a] += 1 if len(list(even.keys())) == 1 and len(list(odd.keys())) =...
p03244
import collections N = int(eval(input())) VV = list(map(int, input().split())) v_even = VV[::2] v_odd = VV[1::2] e = collections.Counter(v_even) o = collections.Counter(v_odd) e_common = e.most_common() o_common = o.most_common() if (e_common[0] != o_common[0]): tmp = e_common[0][1] + o_common[0][...
import collections N = int(eval(input())) VV = list(map(int, input().split())) v_even = VV[::2] v_odd = VV[1::2] e = collections.Counter(v_even).most_common() + [(0, 0)] o = collections.Counter(v_odd).most_common() + [(0, 0)] if (e[0][0] == o[0][0]): tmp1 = e[0][1] + o[1][1] tmp2 = e[1][1] + o[0]...
p03244
import collections n = int(eval(input())) v = list(map(int, input().split())) v1 = [v[i*2+1] for i in range(n//2)] v2 = [v[i*2] for i in range(n//2)] c1 = collections.Counter(v1).most_common() c2 = collections.Counter(v2).most_common() if len(set(v1)) == len(set(v2)) == 1: if c1[0][0] != c2[0][0]: prin...
import collections n = int(eval(input())) v = list(map(int, input().split())) v1 = v[::2] v2 = v[1::2] c1 = collections.Counter(v1).most_common() c2 = collections.Counter(v2).most_common() if c1[0][0] != c2[0][0]: print((len(v1)-c1[0][1] + len(v2)-c2[0][1])) else: if len(c1) == len(c2) == 1: print(...
p03244