結果
| 問題 |
No.1098 LCAs
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-26 22:50:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 742 bytes |
| コンパイル時間 | 1,447 ms |
| コンパイル使用メモリ | 169,404 KB |
| 実行使用メモリ | 813,976 KB |
| 最終ジャッジ日時 | 2024-07-04 22:54:14 |
| 合計ジャッジ時間 | 5,148 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 MLE * 1 |
| other | -- * 28 |
コンパイルメッセージ
main.cpp: In function 'long long int dp(long long int, long long int)':
main.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
28 | }
| ^
ソースコード
#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; }
int n;
vector<int> tree[200010];
int m1[200010];
int m2[200010];
int dp(int idx, int par){
int ans = 1;
int sub = 1;
for(auto e : tree[idx]){
if(e != par){
dp(e, idx);
ans += sub * m2[e] * 2;
sub += m2[e];
}
}
m1[idx] = ans;
m2[idx] = sub;
}
signed main(){
cin >> n;
for(int i = 0;i < n-1;i++){
int u, v;
cin >> u >> v;
u--; v--;
tree[u].push_back(v);
tree[v].push_back(u);
}
dp(0, -1);
for(int i = 0;i < n;i++){
cout << m1[i] << endl;
}
return 0;
}