結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-28 00:56:24 |
| 言語 | Nim (2.2.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 957 bytes |
| コンパイル時間 | 771 ms |
| コンパイル使用メモリ | 65,820 KB |
| 最終ジャッジ日時 | 2024-06-28 20:27:27 |
| 合計ジャッジ時間 | 2,150 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
/home/judge/data/code/Main.nim(16, 38) Error: type mismatch: got 'seq[int]' for 'map(split(readLine(stdin), {' ', '\t', '\v', '\r', '\n', '\f'}, -1), parseInt)' but expected 'tuple'
ソースコード
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()