結果

問題 No.90 品物の並び替え
ユーザー ckawatakckawatak
提出日時 2017-07-17 23:45:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-17 00:08:11
合計ジャッジ時間 1,338 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from collections import deque

class Node():
    def __init__(self, id):
        self.id = id
        self.state = 0
        self.children = []

###

n,m = list(map(int, input().split(' ')))        

scores = []
for i in range(n):
    r = [0] * n
    scores.append(r)

children = {}
for i in range(m):
    p,c,s = list(map(int, input().split(' ')))
    if p not in children:
        children[p] = [c]
    else:
        children[p].append(c)
    scores[p][c] = s

###

nodes = []
for p in range(n):
    nodes.append(Node(p))

for parent in nodes:
    for c in sorted(children[parent.id]):
        parent.children.append(nodes[c])

###

def dfs(parent, parents, sum, sums):
    parent.status = 1
    for child in parent.children:
        if child.status == 0:
            parents.append(parent)
            for p in parents:
                sum += scores[p.id][child.id]
            dfs(child, parents, sum, sums)
        else:
            sums.append(sum)

def reset():
    for node in nodes:
        node.status = 0
        for child in node.children:
            child.status = 0

###

sums = []            
for parent in nodes:
    for child in parent.children:
        reset()
        parent.status = 1        
        dfs(child, [parent], scores[parent.id][child.id], sums)

print(sorted(sums)[len(sums)-1])
0