結果
問題 | No.1507 Road Blocked |
ユーザー |
![]() |
提出日時 | 2022-12-06 21:26:06 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 649 ms / 2,000 ms |
コード長 | 653 bytes |
コンパイル時間 | 235 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 54,784 KB |
最終ジャッジ日時 | 2024-10-13 09:18:44 |
合計ジャッジ時間 | 21,327 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
import syssys.setrecursionlimit(10**7)N = int(input())G = [list() for _ in range(N)]for i in range(N-1):u,v = map(int, input().split())u-=1;v-=1G[u].append(v)G[v].append(u)depth = [0]*Nsub_tree = [0]*Nnum = 0def dfs(G, v, p, d):depth[v] = dfor next_v in G[v]:if next_v == p:continuedfs(G, next_v, v, d+1)sub_tree[v] = 1for c in G[v]:if c== p:continuesub_tree[v] += sub_tree[c]dfs(G,0,-1,0)for i in range(1,N):s = sub_tree[i]num += s*(s-1)//2+(N-s)*(N-s-1)//2mod = 998244353n = (N-1)*N*(N-1)//2print((num*pow(n,mod-2,mod))%mod)