結果

問題 No.2532 Want Play More
ユーザー SSRSSSRS
提出日時 2023-11-03 21:41:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 211,100 KB
実行使用メモリ 28,420 KB
最終ジャッジ日時 2023-11-03 21:42:08
合計ジャッジ時間 6,205 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 218 ms
25,836 KB
testcase_02 AC 216 ms
25,820 KB
testcase_03 AC 211 ms
24,884 KB
testcase_04 AC 206 ms
24,712 KB
testcase_05 AC 197 ms
24,000 KB
testcase_06 AC 146 ms
28,420 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 83 ms
13,956 KB
testcase_11 AC 82 ms
13,548 KB
testcase_12 AC 148 ms
20,016 KB
testcase_13 AC 101 ms
15,556 KB
testcase_14 AC 32 ms
7,456 KB
testcase_15 AC 218 ms
25,612 KB
testcase_16 AC 181 ms
22,324 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 130 ms
17,944 KB
testcase_19 AC 178 ms
22,676 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 110 ms
24,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> p(N, -1);
  vector<vector<int>> c(N);
  vector<int> b;
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    b.push_back(v);
    for (int w : E[v]){
      if (w != p[v]){
        p[w] = v;
        c[v].push_back(w);
        Q.push(w);
      }
    }
  }
  reverse(b.begin(), b.end());
  vector<int> mn(N, INF), mx(N, -INF);
  for (int v : b){
    if (c[v].empty()){
      mn[v] = 0;
      mx[v] = 0;
    } else {
      for (int w : c[v]){
        mn[v] = min(mn[v], mx[w] + 1);
        mx[v] = max(mx[v], mn[w] + 1);
      }
    }
  }
  cout << mx[0] << endl;
  cout << mn[0] << endl;
}
0