Related to: Atcoder
anonymous ベルマンフォード
Python
INF = float('inf')


def Bellmanford(node, edges, source):
    d = [INF] * node  # ある頂点までのコストを保存するリスト
    d[source] = 0

    for i in range(node):
        for start, goal, cost in edges:
            # 辺の始まりの頂点までのコストが INF でなく
            # 辺の向かう先の頂点のコストが、より軽くなる場合に、
            # リストを更新する
            if d[start] != INF and d[start] + cost < d[goal]:
                d[goal] = d[start] + cost
                if i == node-1 and goal == node-1:
                    return 'inf'
    return -d[node-1]


N, M = map(int, input().split())
abc = [map(int, input().split()) for _ in range(M)]
Edges = [None] * M

for i in range(M):
    ai, bi, ci = abc[i]
    Edges[i] = (ai-1, bi-1, -ci)


ans = Bellmanford(N, Edges, 0)
print(ans)

anonymous ABC124 B
Python
N = int(input())
H = list(map(int, input().split()))

res = 0
for i in range(len(H)):
    cnt = 0
    for j in range(0, i):
        if H[j] > H[i]:
            cnt += 1
    if cnt == 0:
        res += 1

print(res)
anonymous ABC123 A
Python
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

k = int(input())

ls = [a, b, c, d, e]

ans = 'Yay!'
for l in ls:
    for n in ls:
        if l - n > k:
            ans = ':('

print(ans)
anonymous ABC124 A
Python
A, B = map(int, input().split())

num = max(A, B)

if A == B:
    print(num + num)
else:
    print(num + num - 1)
anonymous ABC125 B
Python
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

sum = 0

for i in range(N):
    if V[i] - C[i] > 0:
        sum += V[i] - C[i]

print(sum)
anonymous ABC125 A
Python
A, B, T = map(int, input().split())

sum = 0
for s in range(1, T+1):
    if s % A == 0:
        sum += B

print(sum)
anonymous ABC126 B
Python
S = input()

aa = S[0:2]
bb = S[2:4]


def isYY(yy):
    if 0 <= int(yy) and int(yy) <= 99:
        return True
    else:
        return False


def isMM(mm):
    if 1 <= int(mm) and int(mm) <= 12:
        return True
    else:
        return False


ans = []
if isYY(aa) and isMM(bb):
    # YYMM
    ans.append('YYMM')
if isMM(aa) and isYY(bb):
    # MMYY
    ans.append('MMYY')

if len(ans) >= 2:
    print('AMBIGUOUS')
elif len(ans) == 1:
    print(ans[0])
else:
    print('NA')
anonymous ABC127 B
Python
r, D, x2 = map(int, input().split())

for _ in range(0, 10):
    nx = r * x2 - D
    print(nx)
    x2 = nx
anonymous ABC127
Python
A, B = map(int, input().split())

if A >= 13:
    print(B)
elif 6 <= A and A <= 12:
    print(int(B/2))
elif A <= 5:
    print(0)
1