結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
|
提出日時 | 2022-12-12 07:18:41 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,070 bytes |
コンパイル時間 | 1,064 ms |
コンパイル使用メモリ | 130,752 KB |
最終ジャッジ日時 | 2025-01-28 21:44:39 |
合計ジャッジ時間 | 2,047 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:33:8: error: no member named 'function' in namespace 'std' 33 | std::function<void(int, int)> dfs = [&](int u, int p) { | ~~~~~^ main.cpp:33:25: error: expected '(' for function-style cast or type construction 33 | std::function<void(int, int)> dfs = [&](int u, int p) { | ~~~^ main.cpp:33:30: error: expected '(' for function-style cast or type construction 33 | std::function<void(int, int)> dfs = [&](int u, int p) { | ~~~^ main.cpp:33:33: error: use of undeclared identifier 'dfs' 33 | std::function<void(int, int)> dfs = [&](int u, int p) { | ^ main.cpp:39:7: error: use of undeclared identifier 'dfs' 39 | dfs(v, u); | ^ main.cpp:44:3: error: use of undeclared identifier 'dfs' 44 | dfs(0, -1); | ^ 6 errors generated.
ソースコード
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> void solve() { int n; std::cin >> n; std::vector<std::vector<int>> g(n); for (int i = 0; i < n - 1; i++) { int u, v; std::cin >> u >> v; u--, v--; g[u].emplace_back(v); g[v].emplace_back(u); } std::vector dp(n, std::vector(2, 0)); std::function<void(int, int)> dfs = [&](int u, int p) { dp[u][0] = 0; // deleting dp[u][1] = 1; // not deleting for (int v : g[u]) { if (v == p) continue; dfs(v, u); dp[u][0] += std::max(dp[v][0], dp[v][1]); dp[u][1] += std::max(dp[v][0], dp[v][1] - 1); } }; dfs(0, -1); std::cout << std::max(dp[0][0], dp[0][1]) << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); solve(); return 0; }