結果
| 問題 | No.1103 Directed Length Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-28 00:56:24 |
| 言語 | Nim (2.2.8) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 957 bytes |
| 記録 | |
| コンパイル時間 | 556 ms |
| コンパイル使用メモリ | 66,152 KB |
| 最終ジャッジ日時 | 2026-03-17 23:15:46 |
| 合計ジャッジ時間 | 1,780 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
/home/judge/data/code/Main.nim(16, 42) Error: tuple expected for tuple unpacking, but got 'seq[int]'
ソースコード
import strutils, sequtils, math, algorithm
const MOD = 10 ^ 9 + 7
var
graph: seq[seq[int]]
parents, depth, dp: array[1000010, int]
stack0, stack1: seq[int]
proc solve() =
let N = stdin.readLine.parseInt
graph = newSeqWith(N, newSeq[int]())
parents.fill(-1)
var a, b: int
for _ in 0..<N - 1:
(a, b) = stdin.readLine.split.map(parseInt)
a -= 1; b -= 1
graph[a].add(b)
parents[b] = a
let root = find(parents, -1)
stack0 = newSeq[int]()
stack0.add(root)
var cur: int
while stack0.len != 0:
cur = stack0.pop()
for child in graph[cur]:
depth[child] = depth[cur] + 1
stack0.add(child)
stack1.add(child)
for cur in stack1.reversed():
dp[parents[cur]] += dp[cur] + 1
var ans = 0
for n in 0..<N:
ans = (ans + depth[n] * (dp[n] + 1)) mod MOD
echo ans
when is_main_module:
solve()