結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー | silversmith |
提出日時 | 2019-05-05 15:23:21 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,578 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 10,924 KB |
実行使用メモリ | 96,332 KB |
最終ジャッジ日時 | 2023-09-07 06:10:01 |
合計ジャッジ時間 | 8,157 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 721 ms
36,452 KB |
testcase_02 | AC | 1,492 ms
45,488 KB |
testcase_03 | AC | 1,083 ms
40,140 KB |
testcase_04 | AC | 785 ms
37,360 KB |
testcase_05 | AC | 1,026 ms
39,948 KB |
testcase_06 | AC | 1,847 ms
48,740 KB |
testcase_07 | AC | 1,696 ms
48,144 KB |
testcase_08 | AC | 1,161 ms
40,616 KB |
testcase_09 | AC | 763 ms
37,340 KB |
testcase_10 | AC | 394 ms
32,880 KB |
testcase_11 | AC | 1,852 ms
49,000 KB |
testcase_12 | AC | 1,645 ms
46,852 KB |
testcase_13 | AC | 1,619 ms
46,604 KB |
testcase_14 | AC | 1,451 ms
44,996 KB |
testcase_15 | AC | 1,080 ms
39,984 KB |
testcase_16 | AC | 291 ms
31,528 KB |
testcase_17 | AC | 1,042 ms
40,260 KB |
testcase_18 | AC | 1,807 ms
48,780 KB |
testcase_19 | AC | 1,748 ms
47,032 KB |
testcase_20 | AC | 1,661 ms
96,332 KB |
ソースコード
import numpy as np class sol(object): def __init__(self, N, tree): self.N = N self.tree = tree self.dp = np.zeros([N,2], dtype=int) self.visit = [False] * N self.parent = np.array([-1] * N, dtype=int) def dns(self, cur): h = [] h.append(cur) while len(h) > 0: v = h.pop() if len(self.tree[v]) == 1 and self.parent[v] == self.tree[v][0]: self.dp[v,1] = 0 self.dp[v,0] = 1 elif self.visit[v] == False: h.append(v) for child in self.tree[v]: if child != self.parent[v]: h.append(child) self.parent[child] = v else: t_dp = self.dp[self.tree[v]] self.dp[v, 1] = np.sum(np.max(t_dp, axis=1)) t_dp[:,0] -= 1 self.dp[v, 0] = 1 + np.sum(np.max(t_dp, axis=1)) self.visit[v] = True return def ans(self): self.dns(0) return max(self.dp[0,0],self.dp[0,1]) def main(): N=int(input()) tree = [[] for i in range(N)] for _ in range(N -1): e = list(map(int, input().split())) tree[e[0] -1].append(e[1] -1) tree[e[1] -1].append(e[0] -1) print(sol(N, tree).ans()) line_prof = False if line_prof: from line_profiler import LineProfiler profiler = LineProfiler() profiler.add_function(sol.dns) profiler.runcall(main) profiler.print_stats() else: main()