結果

問題 No.1098 LCAs
ユーザー Y17Y17
提出日時 2020-06-26 22:50:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 742 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 166,424 KB
実行使用メモリ 814,568 KB
最終ジャッジ日時 2023-09-18 06:43:46
合計ジャッジ時間 4,370 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘long long int dp(long long int, long long int)’ 内:
main.cpp:28:1: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   28 | }
      | ^

ソースコード

diff #

#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;
}
0