結果
| 問題 | No.1637 Easy Tree Query |
| コンテスト | |
| ユーザー |
kokatsu
|
| 提出日時 | 2021-10-20 00:30:04 |
| 言語 | D (dmd 2.112.0) |
| 結果 |
AC
|
| 実行時間 | 130 ms / 2,000 ms |
| コード長 | 714 bytes |
| 記録 | |
| コンパイル時間 | 1,216 ms |
| コンパイル使用メモリ | 188,596 KB |
| 実行使用メモリ | 14,096 KB |
| 最終ジャッジ日時 | 2026-03-06 18:26:59 |
| 合計ジャッジ時間 | 5,296 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/core/checkedint.d(814): Warning: cannot inline function `core.checkedint.mulu!().mulu`
ulong mulu()(ulong x, uint y, ref bool overflow)
^
ソースコード
import std;
void main() {
int N, Q;
readf("%d %d\n", N, Q);
auto tree = new int[][](N+1);
foreach (i; 0 .. N-1) {
int a, b;
readf("%d %d\n", a, b);
tree[a] ~= b;
tree[b] ~= a;
}
auto seen = new bool[](N+1);
auto part = new long[](N+1);
void dfs(int root) {
seen[root] = true;
++part[root];
foreach (t; tree[root]) {
if (seen[t]) {
continue;
}
dfs(t);
part[root] += part[t];
}
}
dfs(1);
long S;
foreach (i; 0 .. Q) {
long p, x;
readf("%d %d\n", p, x);
S += part[p] * x;
S.writeln;
}
}
kokatsu