結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー | ninja-kid |
提出日時 | 2023-02-10 13:04:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 1,397 bytes |
コンパイル時間 | 4,447 ms |
コンパイル使用メモリ | 265,804 KB |
実行使用メモリ | 18,008 KB |
最終ジャッジ日時 | 2023-09-21 15:31:51 |
合計ジャッジ時間 | 7,968 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
18,008 KB |
testcase_01 | AC | 33 ms
6,776 KB |
testcase_02 | AC | 83 ms
11,472 KB |
testcase_03 | AC | 53 ms
8,932 KB |
testcase_04 | AC | 36 ms
7,404 KB |
testcase_05 | AC | 51 ms
8,700 KB |
testcase_06 | AC | 104 ms
13,396 KB |
testcase_07 | AC | 98 ms
13,060 KB |
testcase_08 | AC | 54 ms
9,292 KB |
testcase_09 | AC | 35 ms
7,036 KB |
testcase_10 | AC | 13 ms
4,804 KB |
testcase_11 | AC | 104 ms
13,668 KB |
testcase_12 | AC | 93 ms
12,676 KB |
testcase_13 | AC | 90 ms
12,288 KB |
testcase_14 | AC | 78 ms
11,208 KB |
testcase_15 | AC | 52 ms
8,832 KB |
testcase_16 | AC | 9 ms
4,380 KB |
testcase_17 | AC | 52 ms
8,848 KB |
testcase_18 | AC | 103 ms
13,324 KB |
testcase_19 | AC | 94 ms
12,664 KB |
testcase_20 | AC | 94 ms
12,488 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace atcoder; using ll = long long; const ll MOD1 = 1000000007LL; const ll MOD2 = 998244353LL; using namespace std; const vector<pair<int, int>> dpos4 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; // const vector<pair<int, int>> dpos8 = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } int main() { int N; cin >> N; vector<vector<int>> edges(N); rep(i, N - 1){ int u, v; cin >> u >> v; u--, v--; edges[u].push_back(v); edges[v].push_back(u); } vector<vector<ll>> dp(N, vector<ll>(2, 0)); auto dfs = [&](auto self, int fr, int prev = -1) -> void { dp[fr][0] = 0; dp[fr][1] = 1; for(auto to: edges[fr]){ if(to == prev) continue; self(self, to, fr); dp[fr][0] += max(dp[to][0], dp[to][1]); dp[fr][1] += max(dp[to][0], dp[to][1] - 1); } }; dfs(dfs, 0); cout << max(dp[0][0], dp[0][1]) << endl; return 0; }