結果

問題 No.763 Noelちゃんと木遊び
ユーザー yelyel
提出日時 2024-05-04 12:54:02
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 3,014 ms
コンパイル使用メモリ 253,684 KB
実行使用メモリ 29,832 KB
最終ジャッジ日時 2024-05-04 12:54:08
合計ジャッジ時間 5,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
29,832 KB
testcase_01 AC 45 ms
20,008 KB
testcase_02 AC 98 ms
21,288 KB
testcase_03 AC 67 ms
20,520 KB
testcase_04 AC 52 ms
20,080 KB
testcase_05 AC 63 ms
20,476 KB
testcase_06 AC 114 ms
21,780 KB
testcase_07 AC 120 ms
21,804 KB
testcase_08 AC 68 ms
20,664 KB
testcase_09 AC 50 ms
19,988 KB
testcase_10 AC 30 ms
19,304 KB
testcase_11 AC 113 ms
22,068 KB
testcase_12 AC 102 ms
21,588 KB
testcase_13 AC 104 ms
21,588 KB
testcase_14 AC 89 ms
21,412 KB
testcase_15 AC 77 ms
20,488 KB
testcase_16 AC 26 ms
19,192 KB
testcase_17 AC 63 ms
20,752 KB
testcase_18 AC 117 ms
21,832 KB
testcase_19 AC 104 ms
21,600 KB
testcase_20 AC 106 ms
21,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int MAX = 1e9;
const int MIN = -1*1e9;
const ll MAXLL = 1e18;
const ll MINLL = -1*1e18;
vector<bool> F(200010);
vector<vector<int>> G(200010);
vector DP(200010,vector<int>(2));

void DFS(int n, int v)
{
	F[n] = true;
    for(auto x : G[n])
    {
        if(F[x] || x == v) continue;
        DFS(x,n);
        DP[n][0] += max(DP[x][0],DP[x][1]);
        DP[n][1] += max(DP[x][0]+1,DP[x][1]);
    }
    if(G[n].size() == 1 && G[n][0] == v) DP[n][1] = MIN;
    //cout << n << " " << DP[n][0] << " " << DP[n][1] << endl;
    return;
}

int main()
{
    int N; cin >> N;
    for(int i = 0; i < N-1; i++)
    {
        int A,B; cin >> A >> B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    DFS(1,-1);
    cout << max(DP[1][0]+1,DP[1][1]) << endl;
    return 0;
}
0