結果

問題 No.763 Noelちゃんと木遊び
ユーザー parsee1053parsee1053
提出日時 2019-06-28 23:56:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 64,904 KB
実行使用メモリ 16,016 KB
最終ジャッジ日時 2023-09-14 22:48:16
合計ジャッジ時間 3,091 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
16,016 KB
testcase_01 AC 29 ms
7,312 KB
testcase_02 AC 73 ms
8,808 KB
testcase_03 AC 46 ms
7,824 KB
testcase_04 AC 33 ms
7,532 KB
testcase_05 AC 47 ms
8,048 KB
testcase_06 AC 93 ms
9,492 KB
testcase_07 AC 86 ms
9,492 KB
testcase_08 AC 49 ms
7,996 KB
testcase_09 AC 33 ms
7,252 KB
testcase_10 AC 13 ms
6,300 KB
testcase_11 AC 88 ms
9,584 KB
testcase_12 AC 79 ms
9,184 KB
testcase_13 AC 75 ms
9,036 KB
testcase_14 AC 67 ms
8,672 KB
testcase_15 AC 46 ms
7,868 KB
testcase_16 AC 9 ms
6,060 KB
testcase_17 AC 47 ms
7,928 KB
testcase_18 AC 91 ms
9,512 KB
testcase_19 AC 76 ms
9,176 KB
testcase_20 AC 78 ms
9,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int n;
vector<int> G[100000];
int dp[100000][2];

void dfs(int x, int p) {
  dp[x][0] = 1;
  dp[x][1] = 0;
  REP(i, G[x].size()) {
    if (G[x][i] == p) continue;
    dfs(G[x][i], x);
    dp[x][0] += max(dp[G[x][i]][0] - 1, dp[G[x][i]][1]);
    dp[x][1] += max(dp[G[x][i]][0], dp[G[x][i]][1]);
  }
}

int main() {
  cin >> n;
  REP(i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0, -1);
  cout << max(dp[0][0], dp[0][1]) << endl;
  return 0;
}
0