結果
問題 | 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 |
コンパイル時間 | 75 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 408,612 KB |
最終ジャッジ日時 | 2024-06-10 03:48:17 |
合計ジャッジ時間 | 6,504 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
17,696 KB |
testcase_01 | AC | 25 ms
10,624 KB |
testcase_02 | AC | 26 ms
10,880 KB |
testcase_03 | AC | 26 ms
10,880 KB |
testcase_04 | AC | 25 ms
10,880 KB |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | AC | 627 ms
59,540 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)