結果
問題 | No.828 全方位神童数 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-05-03 22:07:27 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 301 ms / 2,000 ms |
コード長 | 2,802 bytes |
コンパイル時間 | 2,122 ms |
コンパイル使用メモリ | 115,352 KB |
実行使用メモリ | 29,468 KB |
最終ジャッジ日時 | 2023-09-04 01:04:16 |
合計ジャッジ時間 | 10,949 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 17 ms
5,056 KB |
testcase_04 | AC | 6 ms
4,380 KB |
testcase_05 | AC | 14 ms
4,736 KB |
testcase_06 | AC | 5 ms
4,376 KB |
testcase_07 | AC | 4 ms
4,380 KB |
testcase_08 | AC | 5 ms
4,380 KB |
testcase_09 | AC | 3 ms
4,376 KB |
testcase_10 | AC | 12 ms
4,692 KB |
testcase_11 | AC | 3 ms
4,380 KB |
testcase_12 | AC | 12 ms
4,748 KB |
testcase_13 | AC | 105 ms
8,172 KB |
testcase_14 | AC | 227 ms
15,932 KB |
testcase_15 | AC | 78 ms
7,640 KB |
testcase_16 | AC | 111 ms
9,148 KB |
testcase_17 | AC | 86 ms
7,896 KB |
testcase_18 | AC | 159 ms
14,324 KB |
testcase_19 | AC | 283 ms
20,000 KB |
testcase_20 | AC | 192 ms
14,860 KB |
testcase_21 | AC | 247 ms
15,852 KB |
testcase_22 | AC | 57 ms
6,652 KB |
testcase_23 | AC | 19 ms
5,024 KB |
testcase_24 | AC | 144 ms
12,808 KB |
testcase_25 | AC | 60 ms
7,156 KB |
testcase_26 | AC | 269 ms
16,700 KB |
testcase_27 | AC | 230 ms
16,416 KB |
testcase_28 | AC | 277 ms
19,656 KB |
testcase_29 | AC | 257 ms
16,712 KB |
testcase_30 | AC | 143 ms
11,584 KB |
testcase_31 | AC | 137 ms
10,068 KB |
testcase_32 | AC | 269 ms
15,036 KB |
testcase_33 | AC | 301 ms
20,724 KB |
testcase_34 | AC | 233 ms
16,128 KB |
testcase_35 | AC | 156 ms
14,864 KB |
testcase_36 | AC | 191 ms
15,356 KB |
testcase_37 | AC | 124 ms
9,604 KB |
testcase_38 | AC | 172 ms
14,840 KB |
testcase_39 | AC | 276 ms
20,036 KB |
testcase_40 | AC | 123 ms
10,404 KB |
testcase_41 | AC | 105 ms
7,984 KB |
testcase_42 | AC | 301 ms
22,088 KB |
testcase_43 | AC | 185 ms
29,468 KB |
testcase_44 | AC | 71 ms
12,912 KB |
testcase_45 | AC | 108 ms
17,856 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } int root(int[] uf, int u) { return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u])); } bool connect(int[] uf, int u, int v) { u = uf.root(u); v = uf.root(v); if (u == v) return false; if (uf[u] > uf[v]) swap(u, v); uf[u] += uf[v]; uf[v] = u; return true; } enum MO = 10L^^9 + 7; int N; long[] R; int[] U, V; int[][] G; int[] depth; void dfs(int u, int p, int d) { depth[u] = d; foreach (v; G[u]) { if (v != p) { dfs(v, u, d + 1); } } } void main() { try { for (; ; ) { N = readInt(); R = new long[N]; foreach (u; 0 .. N) { R[u] = readLong(); } U = new int[N - 1]; V = new int[N - 1]; foreach (i; 0 .. N - 1) { U[i] = readInt() - 1; V[i] = readInt() - 1; } auto edges = new Tuple!(int, int)[N - 1]; foreach (i; 0 .. N - 1) { if (U[i] < V[i]) { swap(U[i], V[i]); } edges[i] = tuple(U[i], V[i]); } edges.sort!((a, b) => (a[0] < b[0])); auto uf = new int[N]; uf[] = -1; auto mx = iota(N).array; G = new int[][N]; foreach (e; edges) { const u = uf.root(e[0]); const v = uf.root(e[1]); debug { writeln(e, ": ", mx[u], " ", mx[v]); } G[mx[u]] ~= mx[v]; mx[u] = mx[v] = max(mx[u], mx[v]); uf.connect(u, v); } depth = new int[N]; dfs(N - 1, -1, 0); debug { writeln(depth); } long ans = 1; foreach (u; 0 .. N) { ans *= (R[u] + (depth[u] + 1)); ans %= MO; } writeln(ans); } } catch (EOFException e) { } }