結果
問題 | No.1103 Directed Length Sum |
ユーザー | hedwig100 |
提出日時 | 2020-07-03 22:45:15 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 994 bytes |
コンパイル時間 | 2,029 ms |
コンパイル使用メモリ | 174,124 KB |
実行使用メモリ | 112,608 KB |
最終ジャッジ日時 | 2023-10-17 05:47:43 |
合計ジャッジ時間 | 9,830 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | WA | - |
testcase_03 | AC | 426 ms
40,036 KB |
testcase_04 | AC | 438 ms
29,924 KB |
testcase_05 | AC | 851 ms
49,512 KB |
testcase_06 | AC | 260 ms
20,820 KB |
testcase_07 | AC | 55 ms
7,560 KB |
testcase_08 | AC | 86 ms
9,672 KB |
testcase_09 | AC | 34 ms
5,976 KB |
testcase_10 | AC | 130 ms
11,980 KB |
testcase_11 | AC | 472 ms
32,496 KB |
testcase_12 | AC | 260 ms
20,820 KB |
testcase_13 | AC | 125 ms
12,244 KB |
testcase_14 | AC | 25 ms
5,448 KB |
testcase_15 | AC | 192 ms
16,928 KB |
testcase_16 | AC | 534 ms
36,124 KB |
testcase_17 | AC | 568 ms
37,376 KB |
testcase_18 | AC | 119 ms
11,980 KB |
testcase_19 | AC | 495 ms
33,288 KB |
testcase_20 | AC | 42 ms
6,504 KB |
testcase_21 | AC | 81 ms
9,144 KB |
testcase_22 | AC | 378 ms
27,812 KB |
testcase_23 | AC | 215 ms
17,984 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:48:14: warning: 'root' may be used uninitialized [-Wmaybe-uninitialized] 48 | dist[root] = 0; | ^ main.cpp:41:9: note: 'root' was declared here 41 | int root; | ^~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int N; vector<vector<int>> G; ll ans = 0; vector<int> dist(N); int dfs(int v) { int cnt = 1; for (int e:G[v]) { dist[e] = dist[v] + 1; cnt += dfs(e); } ans += cnt*dist[v]; ans %= MOD; return cnt; } int main(){ cin >> N; G.resize(N); dist.resize(N); fill(dist.begin(),dist.end(),-1); vector<int> deg(N,0); rep(i,N - 1) { int a,b; cin >> a >> b; --a; --b; G[a].push_back(b); deg[b] ++; } int root; rep(i,N) { if (deg[i] == 0) { root = i; break; } } dist[root] = 0; dfs(root); cout << ans << endl; return 0; }