結果

問題 No.2532 Want Play More
ユーザー てんぷらてんぷら
提出日時 2024-08-11 16:54:39
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 5,003 ms
コンパイル使用メモリ 309,168 KB
実行使用メモリ 33,724 KB
最終ジャッジ日時 2024-08-11 16:54:47
合計ジャッジ時間 8,342 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i, n - 1) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector dp(n, vector(2, 0));
    auto dfs = [&](auto &&self, int x, int p) -> void {
        int v0 = inf, v1 = -inf;
        for(auto to : g[x]) {
            if(to == p) {
                continue;
            }
            self(self, to, x);
            v0 = min(v0, dp[to][1] + 1);
            v1 = max(v1, dp[to][0] + 1);
        }
        if(v1 == -inf) {
            v0 = v1 = 0;
        }
        dp[x][0] = v0;
        dp[x][1] = v1;
    };
    dfs(dfs, 0, -1);
    cout << dp[0][1] << endl;
    cout << dp[0][0] << endl;
    return 0;
}
0