結果

問題 No.1582 Vertexes vs Edges
ユーザー rtyurtyu
提出日時 2021-07-08 13:42:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 73,060 KB
実行使用メモリ 9,820 KB
最終ジャッジ日時 2023-09-14 04:48:19
合計ジャッジ時間 3,077 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,984 KB
testcase_01 AC 3 ms
5,728 KB
testcase_02 AC 4 ms
5,720 KB
testcase_03 AC 4 ms
5,716 KB
testcase_04 AC 4 ms
6,108 KB
testcase_05 AC 29 ms
9,228 KB
testcase_06 AC 4 ms
5,896 KB
testcase_07 AC 7 ms
6,252 KB
testcase_08 AC 16 ms
7,456 KB
testcase_09 AC 28 ms
9,128 KB
testcase_10 AC 18 ms
7,852 KB
testcase_11 AC 5 ms
6,076 KB
testcase_12 AC 14 ms
7,316 KB
testcase_13 AC 21 ms
7,952 KB
testcase_14 AC 22 ms
8,052 KB
testcase_15 AC 30 ms
8,972 KB
testcase_16 AC 16 ms
7,368 KB
testcase_17 AC 21 ms
7,892 KB
testcase_18 AC 34 ms
9,756 KB
testcase_19 AC 21 ms
8,064 KB
testcase_20 AC 19 ms
8,016 KB
testcase_21 AC 18 ms
7,544 KB
testcase_22 AC 33 ms
9,120 KB
testcase_23 AC 13 ms
6,932 KB
testcase_24 AC 8 ms
6,332 KB
testcase_25 AC 18 ms
7,496 KB
testcase_26 AC 15 ms
7,136 KB
testcase_27 AC 30 ms
8,844 KB
testcase_28 AC 11 ms
6,676 KB
testcase_29 AC 24 ms
8,300 KB
testcase_30 AC 16 ms
7,408 KB
testcase_31 AC 25 ms
8,380 KB
testcase_32 AC 12 ms
6,884 KB
testcase_33 AC 40 ms
9,820 KB
testcase_34 AC 40 ms
9,752 KB
testcase_35 AC 43 ms
9,800 KB
testcase_36 AC 4 ms
5,836 KB
testcase_37 AC 4 ms
5,720 KB
testcase_38 AC 3 ms
5,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int d[100009][2];
vector<int> v[100009];

void dfs(int n, int p)
{
    d[n][1] = 1;
    for (int i = 0; i < v[n].size(); i++) {
        int tn = v[n][i];
        if (tn == p) continue;
        dfs(tn, n);
        d[n][0] += d[tn][1];
        d[n][1] += min(d[tn][0], d[tn][1]);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        v[a].push_back(b); v[b].push_back(a);
    }
    dfs(1, 0);
    cout << min(d[1][0], d[1][1]) << '\n';
    return 0;
}
0