提出詳細


ソースコード

def riverdown(river):
    global m
    
    gone = [False for _ in range(m)]
    gone[0] = True
    route = [0]
    now = 0
    
    while True:
        tmp = now
        for i in range(m):
            if not gone[i] and river[now][i] > 0:
                now = i
                gone[i] = True
                route.append(i)
                break

        if now == m - 1:
            return route
            
        if now == tmp:
            route = route[:-1]
            if not route:
                return False
            now = route[-1]


for loop in range(int(input())):
    print("Case #{}:".format(loop + 1))
    
    n, m = map(int, input().split())
    
    river = [[0 for i in range(m)] for i in range(m)]
    # river[始点][終点] = 流量
    
    for i in range(n):
        tmp = list(map(int, input().split()))
        river[tmp[0]][tmp[1]] = tmp[2]
        
    maxF = 0

    while True:
        route = riverdown(river)
        if not route:
            break
            
        flow = float("inf")
        for i in range(len(route)-1):
            flow = min(river[route[i]][route[i+1]], flow)
        
        maxF += flow
        for i in range(len(route)-1):
            river[route[i]][route[i+1]] -= flow
            river[route[i+1]][route[i]] += flow
            
    print(maxF)
    

提出情報

提出時間 2020-11-23 00:48:32
問題 K - 異世界はウォーターゲートとともに。
ユーザ名 konchan
状態 正解
正解率 50/50
提出出力結果

テストケース情報

# 状態 詳細情報
テストケース 1 正解 詳細を見る
テストケース 2 正解 詳細を見る
テストケース 3 正解 詳細を見る
テストケース 4 正解 詳細を見る
テストケース 5 正解 詳細を見る
テストケース 6 正解 詳細を見る
テストケース 7 正解 詳細を見る
テストケース 8 正解 詳細を見る
テストケース 9 正解 詳細を見る
テストケース 10 正解 詳細を見る
テストケース 11 正解 詳細を見る
テストケース 12 正解 詳細を見る
テストケース 13 正解 詳細を見る
テストケース 14 正解 詳細を見る
テストケース 15 正解 詳細を見る
テストケース 16 正解 詳細を見る
テストケース 17 正解 詳細を見る
テストケース 18 正解 詳細を見る
テストケース 19 正解 詳細を見る
テストケース 20 正解 詳細を見る
テストケース 21 正解 詳細を見る
テストケース 22 正解 詳細を見る
テストケース 23 正解 詳細を見る
テストケース 24 正解 詳細を見る
テストケース 25 正解 詳細を見る
テストケース 26 正解 詳細を見る
テストケース 27 正解 詳細を見る
テストケース 28 正解 詳細を見る
テストケース 29 正解 詳細を見る
テストケース 30 正解 詳細を見る
テストケース 31 正解 詳細を見る
テストケース 32 正解 詳細を見る
テストケース 33 正解 詳細を見る
テストケース 34 正解 詳細を見る
テストケース 35 正解 詳細を見る
テストケース 36 正解 詳細を見る
テストケース 37 正解 詳細を見る
テストケース 38 正解 詳細を見る
テストケース 39 正解 詳細を見る
テストケース 40 正解 詳細を見る
テストケース 41 正解 詳細を見る
テストケース 42 正解 詳細を見る
テストケース 43 正解 詳細を見る
テストケース 44 正解 詳細を見る
テストケース 45 正解 詳細を見る
テストケース 46 正解 詳細を見る
テストケース 47 正解 詳細を見る
テストケース 48 正解 詳細を見る
テストケース 49 正解 詳細を見る
テストケース 50 正解 詳細を見る