結果

問題 No.763 Noelちゃんと木遊び
ユーザー polyomino_24polyomino_24
提出日時 2018-12-12 00:40:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 104,552 KB
実行使用メモリ 18,456 KB
最終ジャッジ日時 2023-10-24 22:29:48
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
18,456 KB
testcase_01 AC 28 ms
8,196 KB
testcase_02 AC 73 ms
9,964 KB
testcase_03 AC 47 ms
8,976 KB
testcase_04 AC 35 ms
8,380 KB
testcase_05 AC 46 ms
8,912 KB
testcase_06 AC 89 ms
10,556 KB
testcase_07 AC 84 ms
10,444 KB
testcase_08 AC 50 ms
9,076 KB
testcase_09 AC 33 ms
8,328 KB
testcase_10 AC 14 ms
7,452 KB
testcase_11 AC 91 ms
10,616 KB
testcase_12 AC 77 ms
10,260 KB
testcase_13 AC 77 ms
10,204 KB
testcase_14 AC 67 ms
9,844 KB
testcase_15 AC 45 ms
8,944 KB
testcase_16 AC 10 ms
7,228 KB
testcase_17 AC 47 ms
8,960 KB
testcase_18 AC 91 ms
10,572 KB
testcase_19 AC 80 ms
10,296 KB
testcase_20 AC 82 ms
10,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
vector<int>g[123456];
int dp[123456][2];
void dfs(int cur,int par){
    dp[cur][0] = 1;
    for(int x:g[cur]){
        if(x!=par){
            dfs(x,cur);
            dp[cur][0] += max(dp[x][0]-1,dp[x][1]);
            dp[cur][1] += max(dp[x][0],dp[x][1]);
        }
    }
}
int main(){
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a>> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,-1);
    cout << max(dp[0][0], dp[0][1]) << endl;
}
0