結果
問題 |
No.1103 Directed Length Sum
|
ユーザー |
![]() |
提出日時 | 2020-07-03 21:50:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 819 bytes |
コンパイル時間 | 706 ms |
コンパイル使用メモリ | 85,576 KB |
実行使用メモリ | 109,776 KB |
最終ジャッジ日時 | 2024-09-17 00:11:24 |
合計ジャッジ時間 | 7,412 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 WA * 1 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:43:8: warning: 'r' may be used uninitialized [-Wmaybe-uninitialized] 43 | dfs(r, 0); | ~~~^~~~~~ main.cpp:36:9: note: 'r' was declared here 36 | int r; | ^
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; ll N; int par[1000001]; vector<int> G[1000000]; bool used[1000000]; ll ans; void dfs(int v,int d){ used[v] = true; ans += (d*(d+1))/2; for(int to : G[v]){ if(!used[to]) dfs(to, d+1); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N; for(int i = 0; i < N-1; i++){ int a, b; cin >> a >> b; par[b] = a; a--; b--; G[a].push_back(b); G[b].push_back(a); } int r; for(int i = 1; i <= N; i++){ if(par[i] == 0){ r = i-1; break; } } dfs(r, 0); cout << ans << endl; }