結果
問題 | No.2532 Want Play More |
ユーザー |
![]() |
提出日時 | 2023-11-03 23:10:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 263 ms / 2,000 ms |
コード長 | 698 bytes |
コンパイル時間 | 2,222 ms |
コンパイル使用メモリ | 200,220 KB |
最終ジャッジ日時 | 2025-02-17 18:48:54 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {int N;cin >> N;vector<vector<int>> G(N);for( int i = 0; i < N-1; i++ ) {int a, b;cin >> a >> b;a--, b--;G[a].push_back(b);G[b].push_back(a);}vector<vector<int>> dp(N, vector<int>(2));for( int i = 0; i < N; i++ ) {dp[i][0] = 0;dp[i][1] = ( i != 0 && G[i].size() == 1 ? 0 : N-1 );}auto dfs = [&](auto dfs, int cur, int pre) -> void {for( int &nxt : G[cur] ) {if( nxt != pre ) dfs(dfs, nxt, cur);}if( pre != -1 ) {dp[pre][0] = max(dp[pre][0], dp[cur][1]+1);dp[pre][1] = min(dp[pre][1], dp[cur][0]+1);}};dfs(dfs, 0, -1);cout << dp[0][0] << endl;cout << dp[0][1] << endl;}