結果

問題 No.2598 Kadomatsu on Tree
ユーザー 👑 seekworserseekworser
提出日時 2024-01-03 04:51:50
言語 Nim
(2.0.2)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 621 bytes
コンパイル時間 3,579 ms
コンパイル使用メモリ 65,992 KB
実行使用メモリ 53,848 KB
最終ジャッジ日時 2024-01-03 04:52:08
合計ジャッジ時間 15,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 6 ms
6,676 KB
testcase_14 AC 6 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 7 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 244 ms
26,424 KB
testcase_24 AC 281 ms
26,728 KB
testcase_25 AC 251 ms
26,740 KB
testcase_26 AC 251 ms
26,616 KB
testcase_27 AC 249 ms
26,644 KB
testcase_28 AC 265 ms
26,728 KB
testcase_29 AC 259 ms
26,956 KB
testcase_30 AC 259 ms
26,448 KB
testcase_31 AC 258 ms
26,744 KB
testcase_32 AC 255 ms
26,696 KB
testcase_33 AC 277 ms
27,004 KB
testcase_34 AC 245 ms
26,344 KB
testcase_35 AC 262 ms
27,040 KB
testcase_36 AC 261 ms
27,020 KB
testcase_37 AC 274 ms
27,004 KB
testcase_38 AC 268 ms
27,060 KB
testcase_39 AC 264 ms
27,060 KB
testcase_40 AC 260 ms
27,060 KB
testcase_41 AC 265 ms
27,060 KB
testcase_42 AC 278 ms
27,060 KB
testcase_43 AC 258 ms
27,060 KB
testcase_44 AC 260 ms
27,060 KB
testcase_45 AC 260 ms
27,060 KB
testcase_46 AC 277 ms
27,060 KB
testcase_47 AC 259 ms
27,060 KB
testcase_48 AC 274 ms
53,848 KB
testcase_49 AC 23 ms
7,808 KB
testcase_50 AC 172 ms
35,072 KB
testcase_51 AC 46 ms
14,208 KB
testcase_52 AC 75 ms
16,384 KB
testcase_53 AC 101 ms
13,824 KB
testcase_54 AC 79 ms
11,520 KB
testcase_55 AC 32 ms
6,676 KB
testcase_56 AC 150 ms
19,584 KB
testcase_57 AC 55 ms
8,576 KB
testcase_58 AC 246 ms
26,676 KB
testcase_59 AC 247 ms
26,744 KB
testcase_60 AC 260 ms
46,808 KB
testcase_61 AC 292 ms
50,172 KB
testcase_62 AC 265 ms
43,892 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(24, 8) Warning: Number of spaces around '!=' is not consistent [Spacing]

ソースコード

diff #

import strutils,sequtils
var m=998244353
var n=stdin.readLine.parseint
var g=newSeqWith(n,newSeq[int](0))
for i in 0..<n-1:
 var u=stdin.readline.split.map(parseint).mapit(it-1)
 g[u[0]].add(u[1])
 g[u[1]].add(u[0])
var a=stdin.readLine.split.map(parseInt)
var ans=0
proc dfs(x,par:int):int=
 result=1
 var tl,tu=0
 for y in g[x]:
  if y==par: continue
  var sz=dfs(y,x)
  result+=sz
  if a[y]<a[x]:
   ans+=(tl*sz)mod m
   tl+=sz
  if a[x]<a[y]:
   ans+=(tu*sz)mod m
   tu+=sz
 if par!= -1:
  if a[par]<a[x]: ans+=(tl*(n-result))mod m
  if a[x]<a[par]: ans+=(tu*(n-result))mod m
 ans=ans mod m
discard dfs(0,-1)
echo ans
0