結果
| 問題 | No.763 Noelちゃんと木遊び | 
| コンテスト | |
| ユーザー |  t33f | 
| 提出日時 | 2018-12-11 18:28:28 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,529 ms / 2,000 ms | 
| コード長 | 735 bytes | 
| コンパイル時間 | 665 ms | 
| コンパイル使用メモリ | 68,044 KB | 
| 実行使用メモリ | 20,812 KB | 
| 最終ジャッジ日時 | 2025-03-22 10:33:38 | 
| 合計ジャッジ時間 | 24,892 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         int x, y; scanf(" %d %d", &x, &y);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <vector>
#include <cstdio>
#include <iostream>
using namespace std;
vector<int> adj[100100];
int memo[2][100100];
int calc(int i, int use, int p = -1) {
    if (memo[use][i] >= 0) return memo[use][i];
    int sum = use;
    for (int j : adj[i])
        if (j != p)
            sum += use ? calc(j, 0, i) : max(calc(j, 0, i), calc(j, 1, i));
    cerr << use << ' ' << i << ' ' << sum << endl;
    return memo[use][i] = sum;
}
int main() {
    int n; cin >> n;
    for (int i = 1; i < n; i++) {
        int x, y; scanf(" %d %d", &x, &y);
        adj[x].push_back(y); adj[y].push_back(x);
    }
    fill(memo[0], memo[0] + n + 1, -1);
    fill(memo[1], memo[1] + n + 1, -1);
    cout << max(calc(1, 1), calc(1, 0)) << endl;
}
            
            
            
        