結果

問題 No.1928 Make a Binary Tree
ユーザー milanis48663220milanis48663220
提出日時 2022-05-06 21:39:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,776 bytes
コンパイル時間 1,305 ms
コンパイル使用メモリ 121,748 KB
実行使用メモリ 33,544 KB
最終ジャッジ日時 2023-09-20 02:31:53
合計ジャッジ時間 7,363 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 66 ms
24,712 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 91 ms
24,288 KB
testcase_40 AC 91 ms
24,348 KB
testcase_41 AC 91 ms
24,356 KB
testcase_42 AC 89 ms
24,232 KB
testcase_43 AC 92 ms
24,360 KB
testcase_44 AC 91 ms
24,420 KB
testcase_45 AC 91 ms
24,340 KB
testcase_46 AC 89 ms
24,224 KB
testcase_47 AC 92 ms
24,344 KB
testcase_48 AC 94 ms
24,340 KB
testcase_49 AC 77 ms
33,544 KB
testcase_50 AC 131 ms
14,840 KB
testcase_51 AC 133 ms
14,788 KB
testcase_52 AC 133 ms
14,856 KB
testcase_53 AC 136 ms
14,800 KB
testcase_54 AC 126 ms
14,792 KB
testcase_55 AC 67 ms
24,092 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 81 ms
15,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0; i < n-1; i++){
        int u, v; cin >> u >> v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> dp(n);
    function<void(int, int)> dfs = [&](int v, int par){
        int cnt = 0;
        for(int to: g[v]){
            if(to == par) continue;
            dfs(to, v);
            cnt += dp[to]+1;
        }
        dp[v] = max(0, cnt-2);
    };
    dfs(0, -1);
    cout << n-dp[0] << endl;
}
0