結果
問題 |
No.1103 Directed Length Sum
|
ユーザー |
|
提出日時 | 2020-07-03 22:19:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 721 bytes |
コンパイル時間 | 1,566 ms |
コンパイル使用メモリ | 171,536 KB |
実行使用メモリ | 98,904 KB |
最終ジャッジ日時 | 2024-09-17 03:10:30 |
合計ジャッジ時間 | 11,663 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define int long long vector<int> tree[1000010]; int rtree[1000010]; int dfs(int i, int j){ int ans = (j*(j+1))/2; for(auto e : tree[i]){ ans += dfs(e, j+1); } return ans; } signed main(){ int n; cin >> n; int a, b; memset(rtree, -1, sizeof(rtree)); for(int i = 0;i < n-1;i++){ cin >> a >> b; a--; b--; tree[a].push_back(b); rtree[b] = a; } int root = 0; while(rtree[root] != -1) root = rtree[root]; cout << dfs(root, 0) << endl; return 0; }