結果
問題 | No.1098 LCAs |
ユーザー |
![]() |
提出日時 | 2020-06-26 21:43:53 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,130 ms / 2,000 ms |
コード長 | 659 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 75,000 KB |
最終ジャッジ日時 | 2024-07-04 20:27:06 |
合計ジャッジ時間 | 15,512 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
# coding: utf-8# Your code here!import sysread = sys.stdin.readreadline = sys.stdin.readlinen,*vw = map(int,read().split())m = iter(vw)g = [[] for _ in range(n)]for v,w in zip(m,m):g[v-1].append(w-1)g[w-1].append(v-1)order = []parent = [-1]*nst = [0]while st:v = st.pop()order.append(v)for c in g[v]:if c != parent[v]:parent[c] = vst.append(c)res = [1]*nfor i in order[:0:-1]:res[parent[i]] += res[i]for i in range(n):res[i] *= res[i]for i in order[1:]:res[parent[i]] -= res[i]print(*res,sep="\n")