結果

問題 No.2532 Want Play More
ユーザー tnakao0123tnakao0123
提出日時 2023-11-09 14:34:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 52,808 KB
実行使用メモリ 17,856 KB
最終ジャッジ日時 2023-11-09 14:34:24
合計ジャッジ時間 5,230 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,280 KB
testcase_01 AC 192 ms
17,292 KB
testcase_02 AC 164 ms
17,292 KB
testcase_03 AC 155 ms
17,036 KB
testcase_04 AC 152 ms
16,968 KB
testcase_05 AC 150 ms
16,792 KB
testcase_06 AC 66 ms
17,200 KB
testcase_07 AC 5 ms
10,396 KB
testcase_08 AC 8 ms
10,556 KB
testcase_09 AC 7 ms
10,512 KB
testcase_10 AC 68 ms
13,604 KB
testcase_11 AC 65 ms
13,540 KB
testcase_12 AC 138 ms
15,584 KB
testcase_13 AC 79 ms
14,176 KB
testcase_14 AC 20 ms
11,576 KB
testcase_15 AC 157 ms
17,208 KB
testcase_16 AC 133 ms
16,236 KB
testcase_17 AC 7 ms
10,472 KB
testcase_18 AC 94 ms
14,864 KB
testcase_19 AC 133 ms
16,392 KB
testcase_20 AC 5 ms
10,280 KB
testcase_21 AC 4 ms
10,280 KB
testcase_22 AC 3 ms
8,124 KB
testcase_23 AC 4 ms
10,280 KB
testcase_24 AC 5 ms
10,280 KB
testcase_25 AC 5 ms
10,280 KB
testcase_26 AC 5 ms
10,280 KB
testcase_27 AC 5 ms
10,280 KB
testcase_28 AC 55 ms
17,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2532.cc:  No.2532 Want Play More - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];
int ps[MAX_N], cis[MAX_N], dp0[MAX_N], dp1[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    nbrs[u].push_back(v);
    nbrs[v].push_back(u);
  }

  if (n == 1) { printf("0\n0\n"); return 0; }
  
  fill(dp1, dp1 + n, INF);
  ps[0] = -1;

  for (int u = 0; u >= 0;) {
    vi &nbru = nbrs[u];
    int up = ps[u];

    if (cis[u] < nbru.size()) {
      int v = nbru[cis[u]++];
      if (v != up) {
	ps[v] = u;
	u = v;
      }
    }
    else {
      if (u > 0 && nbru.size() == 1)
	dp0[u] = dp1[u] = 0;
      if (up >= 0) {
	dp0[up] = max(dp0[up], dp1[u] + 1);
	dp1[up] = min(dp1[up], dp0[u] + 1);
      }
      u = up;
    }
  }

  printf("%d\n%d\n", dp0[0], dp1[0]);
  
  return 0;
}
0