結果
問題 | No.1103 Directed Length Sum |
ユーザー | takumat |
提出日時 | 2020-07-04 20:16:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,503 ms / 3,000 ms |
コード長 | 1,278 bytes |
コンパイル時間 | 1,716 ms |
コンパイル使用メモリ | 111,224 KB |
実行使用メモリ | 151,744 KB |
最終ジャッジ日時 | 2023-10-19 13:32:38 |
合計ジャッジ時間 | 21,904 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 1,214 ms
151,744 KB |
testcase_03 | AC | 953 ms
73,600 KB |
testcase_04 | AC | 1,281 ms
43,100 KB |
testcase_05 | AC | 2,503 ms
71,752 KB |
testcase_06 | AC | 764 ms
29,244 KB |
testcase_07 | AC | 132 ms
9,600 KB |
testcase_08 | AC | 216 ms
12,768 KB |
testcase_09 | AC | 72 ms
7,224 KB |
testcase_10 | AC | 311 ms
16,132 KB |
testcase_11 | AC | 1,464 ms
46,416 KB |
testcase_12 | AC | 797 ms
29,196 KB |
testcase_13 | AC | 336 ms
16,660 KB |
testcase_14 | AC | 51 ms
6,168 KB |
testcase_15 | AC | 571 ms
23,456 KB |
testcase_16 | AC | 1,629 ms
51,892 KB |
testcase_17 | AC | 1,771 ms
54,004 KB |
testcase_18 | AC | 305 ms
16,132 KB |
testcase_19 | AC | 1,481 ms
47,784 KB |
testcase_20 | AC | 91 ms
8,016 KB |
testcase_21 | AC | 193 ms
11,976 KB |
testcase_22 | AC | 1,177 ms
39,668 KB |
testcase_23 | AC | 619 ms
25,040 KB |
ソースコード
#include <stdio.h> #include <string.h> #include <limits.h> #include <math.h> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <map> #include <set> #include <stack> #include <queue> typedef unsigned long long ULLONG; typedef long long LLONG; static const LLONG MOD_NUM = 1000000007;//998244353; template<class _T> static void getval(_T& a) { std::cin >> a; } template<class _T> static void getval(_T& a, _T& b) { std::cin >> a >> b; } template<class _T> static void getval(_T& a, _T& b, _T& c) { std::cin >> a >> b >> c; } static void exec(); int main() { exec(); fflush(stdout); return 0; } static LLONG dfs(std::vector<std::vector<int>>& graph, int here, int pass) { LLONG ans = 0; for (auto it = graph[here].begin(); it != graph[here].end(); it++) { ans = (ans + dfs(graph, *it, pass + 1)) % MOD_NUM; } ans += ((LLONG)pass * (LLONG)(pass + 1LL) / 2LL) % MOD_NUM; ans %= MOD_NUM; return ans; } static void exec() { int N; getval(N); std::set<int> vers; for (int i = 0; i < N; i++) { vers.insert(i); } std::vector<std::vector<int>> graph(N); for (int i = 1; i < N; i++) { int a, b; getval(a, b); a--; b--; graph[a].push_back(b); vers.erase(b); } printf("%lld\n", dfs(graph, *(vers.begin()), 0)); }