結果
| 問題 | No.763 Noelちゃんと木遊び | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-02-01 14:30:26 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 83 ms / 2,000 ms | 
| コード長 | 1,580 bytes | 
| コンパイル時間 | 1,205 ms | 
| コンパイル使用メモリ | 117,136 KB | 
| 実行使用メモリ | 22,144 KB | 
| 最終ジャッジ日時 | 2025-03-22 10:37:08 | 
| 合計ジャッジ時間 | 3,324 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:69:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |                 scanf("%d %d", &u, &v);
      |                 ~~~~~^~~~~~~~~~~~~~~~~
            
            ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
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; }
const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int n;
vector<vector<int>> g;
vector<vector<int>> dp;
void dfs(int cur, int pre) {
	for (auto next : g[cur]) {
		if (next == pre) continue;
		dfs(next, cur);
	}
	int re = 1;
	int er = 0;
	for (auto next : g[cur]) {
		if (next == pre) continue;
		er += max(dp[next][0], dp[next][1]);
		re += max(dp[next][0] - 1, dp[next][1]);
	}
	dp[cur][0] = re;
	dp[cur][1] = er;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%d", &n);
	g = vector<vector<int>>(n);
	dp = vector<vector<int>>(n, vector<int>(2));
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--; v--;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	dfs(0, -1);
	cout << max(dp[0][0], dp[0][1]) << endl;
	return 0;
}
            
            
            
        