結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 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 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 5 ms
6,676 KB
testcase_14 AC 7 ms
6,676 KB
testcase_15 AC 5 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 7 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 264 ms
26,424 KB
testcase_24 AC 286 ms
26,728 KB
testcase_25 AC 266 ms
26,740 KB
testcase_26 AC 262 ms
26,616 KB
testcase_27 AC 280 ms
26,644 KB
testcase_28 AC 298 ms
26,728 KB
testcase_29 AC 276 ms
26,956 KB
testcase_30 AC 266 ms
26,448 KB
testcase_31 AC 273 ms
26,744 KB
testcase_32 AC 292 ms
26,696 KB
testcase_33 AC 276 ms
27,004 KB
testcase_34 AC 265 ms
26,344 KB
testcase_35 AC 269 ms
27,040 KB
testcase_36 AC 299 ms
27,020 KB
testcase_37 AC 266 ms
27,004 KB
testcase_38 AC 262 ms
27,060 KB
testcase_39 AC 268 ms
27,060 KB
testcase_40 AC 274 ms
27,060 KB
testcase_41 AC 292 ms
27,060 KB
testcase_42 AC 262 ms
27,060 KB
testcase_43 AC 259 ms
27,060 KB
testcase_44 AC 263 ms
27,060 KB
testcase_45 AC 290 ms
27,060 KB
testcase_46 AC 265 ms
27,060 KB
testcase_47 AC 267 ms
27,060 KB
testcase_48 WA -
testcase_49 AC 23 ms
7,808 KB
testcase_50 AC 179 ms
35,072 KB
testcase_51 AC 52 ms
14,208 KB
testcase_52 WA -
testcase_53 AC 99 ms
13,824 KB
testcase_54 AC 83 ms
11,520 KB
testcase_55 AC 34 ms
6,676 KB
testcase_56 AC 155 ms
19,584 KB
testcase_57 AC 59 ms
8,576 KB
testcase_58 AC 249 ms
26,676 KB
testcase_59 AC 282 ms
26,744 KB
testcase_60 AC 273 ms
46,808 KB
testcase_61 AC 290 ms
50,172 KB
testcase_62 AC 270 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