結果
問題 | No.778 クリスマスツリー |
ユーザー | silversmith |
提出日時 | 2019-05-02 00:55:13 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,083 bytes |
コンパイル時間 | 393 ms |
コンパイル使用メモリ | 10,892 KB |
実行使用メモリ | 76,940 KB |
最終ジャッジ日時 | 2023-08-30 04:32:25 |
合計ジャッジ時間 | 9,166 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
7,972 KB |
testcase_01 | AC | 16 ms
7,764 KB |
testcase_02 | AC | 16 ms
7,804 KB |
testcase_03 | AC | 16 ms
7,876 KB |
testcase_04 | AC | 16 ms
7,800 KB |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | AC | 940 ms
60,140 KB |
testcase_08 | RE | - |
testcase_09 | TLE | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
ソースコード
class Node: def __init__(self): #self.parent_Node = None self.child_Node = [] self.flag = False self.fix = False self.all_child = [] def fix_all_child(self): if self.fix: return self.all_child self.all_child = self.child_Node for node in self.child_Node: self.all_child.extend(node.fix_all_child()) self.fix = True return self.all_child class tree: def __init__(self, Nodes): self.Nodes = Nodes def push_edge(self,low, upper): self.Nodes[upper].child_Node.append(self.Nodes[low]) #self.Nodes[low].parent_Node = self.Nodes[upper] def fix_all_child(self, Node_idx): self.Nodes[Node_idx].fix_all_child() N = int(input()) A = map(int, input().split()) t = tree([Node() for i in range(N)]) for idx, a in enumerate(A): t.push_edge(idx + 1, a) t.fix_all_child(0) num = 0 for i in range(N-1, -1, -1): num+=sum([1 if node.flag else 0 for node in t.Nodes[i].all_child]) t.Nodes[i].flag = True print(num)