結果
| 問題 | No.1582 Vertexes vs Edges | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-07-08 13:42:34 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 45 ms / 2,000 ms | 
| コード長 | 648 bytes | 
| コンパイル時間 | 649 ms | 
| コンパイル使用メモリ | 72,304 KB | 
| 実行使用メモリ | 9,728 KB | 
| 最終ジャッジ日時 | 2024-07-01 12:30:49 | 
| 合計ジャッジ時間 | 2,687 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
#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;
}
            
            
            
        