結果

問題 No.2532 Want Play More
ユーザー RubikunRubikun
提出日時 2023-11-03 21:52:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 2,371 ms
コンパイル使用メモリ 204,276 KB
実行使用メモリ 29,840 KB
最終ジャッジ日時 2023-11-03 21:52:13
合計ジャッジ時間 4,526 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,092 KB
testcase_01 AC 92 ms
17,452 KB
testcase_02 AC 92 ms
17,456 KB
testcase_03 AC 86 ms
17,200 KB
testcase_04 AC 85 ms
17,132 KB
testcase_05 AC 83 ms
16,960 KB
testcase_06 AC 66 ms
29,840 KB
testcase_07 AC 5 ms
11,196 KB
testcase_08 AC 6 ms
11,344 KB
testcase_09 AC 5 ms
11,308 KB
testcase_10 AC 37 ms
14,064 KB
testcase_11 AC 37 ms
14,008 KB
testcase_12 AC 66 ms
15,836 KB
testcase_13 AC 68 ms
14,580 KB
testcase_14 AC 17 ms
12,256 KB
testcase_15 AC 92 ms
17,376 KB
testcase_16 AC 74 ms
16,408 KB
testcase_17 AC 6 ms
11,264 KB
testcase_18 AC 55 ms
15,188 KB
testcase_19 AC 76 ms
16,556 KB
testcase_20 AC 4 ms
11,092 KB
testcase_21 AC 4 ms
11,092 KB
testcase_22 AC 3 ms
11,092 KB
testcase_23 AC 4 ms
11,092 KB
testcase_24 AC 4 ms
11,092 KB
testcase_25 AC 4 ms
11,092 KB
testcase_26 AC 4 ms
11,092 KB
testcase_27 AC 3 ms
11,092 KB
testcase_28 AC 44 ms
17,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

vector<int> G[MAX];

int dp[MAX];

int solve(int u,int p,int d){
    if(d%2==0){
        int re=0;
        for(int to:G[u]){
            if(to==p) continue;
            chmax(re,solve(to,u,d^1)+1);
        }
        return re;
    }else{
        int re=INF;
        for(int to:G[u]){
            if(to==p) continue;
            chmin(re,solve(to,u,d^1)+1);
        }
        if(re==INF) re=0;
        return re;
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>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);
    }
    
    cout<<solve(0,-1,0)<<endl;
    cout<<solve(0,-1,1)<<endl;

}
0