結果

問題 No.763 Noelちゃんと木遊び
ユーザー toshiki_fulltoshiki_full
提出日時 2019-02-23 00:33:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 205,296 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-05-04 18:31:38
合計ジャッジ時間 4,488 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
18,816 KB
testcase_01 AC 13 ms
5,376 KB
testcase_02 AC 29 ms
8,192 KB
testcase_03 AC 19 ms
6,656 KB
testcase_04 AC 18 ms
5,632 KB
testcase_05 AC 24 ms
6,528 KB
testcase_06 AC 50 ms
9,216 KB
testcase_07 AC 47 ms
8,960 KB
testcase_08 AC 29 ms
6,784 KB
testcase_09 AC 17 ms
5,632 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 56 ms
9,344 KB
testcase_12 AC 48 ms
8,576 KB
testcase_13 AC 47 ms
8,576 KB
testcase_14 AC 39 ms
7,936 KB
testcase_15 AC 26 ms
6,528 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 20 ms
6,528 KB
testcase_18 AC 38 ms
9,216 KB
testcase_19 AC 37 ms
8,704 KB
testcase_20 AC 35 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
vector<int> dp, ep;
void dfs (int crr, int prt) {
  dp[crr] = 1;
  ep[crr] = 0;
  for (int nxt : grh[crr]) {
    if (nxt == prt) continue;
    dfs(nxt, crr);
    dp[crr] += ep[nxt];
    ep[crr] += max(dp[nxt], ep[nxt]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  grh.resize(n);
  dp.resize(n);
  ep.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int s, t;
    cin >> s >> t;
    grh[--s].push_back(--t);
    grh[t].push_back(s);
  }
  dfs(0, 0);
  int ret = max(dp[0], ep[0]);
  cout << ret << '\n';
  return 0;
}
0