結果

問題 No.90 品物の並び替え
ユーザー mlihua09mlihua09
提出日時 2020-08-23 13:05:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,102 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 84,672 KB
最終ジャッジ日時 2024-04-23 17:34:43
合計ジャッジ時間 6,839 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,808 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #



N, M = map(int, input().split())

item = [list(map(int, input().split())) for i in range(M)]

from itertools import product

ans = 0

from collections import deque

for i in product(range(2), repeat=M):
    
    X = [[] for i in range(N)]
    
    Y = 0
    
    for j in range(M):
        
        if i[j]:
            
            item1, item2, score = item[j]
            
            X[item1] += [item2]
            
            Y += score
            
    
    for j in range(N):
        
        visited = [0] * N
        
        visited[j] = 1
        
        que = deque([j])
        
        while que and Y:
            
            
            q = que.popleft()
            
            for x in X[q]:
                
                if x == j:
                    
                    Y = 0
                    break
                
                if visited[x] == 0:
                    
                    visited[x] = 1
                    
                    que.append(x)
        
        
        if Y == 0:
            break
    
    
    ans = max(ans, Y)
    
print(ans)
0