結果

問題 No.1752 Up-Down Tree
ユーザー 👑 NachiaNachia
提出日時 2021-11-19 22:07:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 1,077 ms
コンパイル使用メモリ 86,240 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2023-08-30 08:39:50
合計ジャッジ時間 2,950 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
10,516 KB
testcase_01 AC 51 ms
10,560 KB
testcase_02 AC 34 ms
11,008 KB
testcase_03 AC 32 ms
11,040 KB
testcase_04 AC 45 ms
11,012 KB
testcase_05 AC 49 ms
10,856 KB
testcase_06 AC 40 ms
10,832 KB
testcase_07 AC 43 ms
10,948 KB
testcase_08 AC 28 ms
8,268 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,384 KB
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <atcoder/modint>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)

using m32 = atcoder::static_modint<1'000'000'007>;

int main(){
  int N; cin >> N;
  vector<vector<int>> E(N);
  rep(i,N-1){
    int u,v; cin >> u >> v; u--; v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }

  vector<int> I = {0};
  vector<int> P(N,-1);
  vector<int> D(N,0);
  rep(i,I.size()){
    int p = I[i];
    for(int e : E[p]) if(P[p] != e){
      P[e] = p;
      D[e] = D[p] + 1;
      I.push_back(e);
    }
  }

  vector<int> Z(N,1);
  for(int i=N-1; i>=1; i--) Z[P[I[i]]] += Z[I[i]];

  vector<int> dpW(N,0);
  for(int i=N-1; i>=0; i--){
    int p = I[i];
    int sumCollected = 0;
    for(int e : E[p]) if(P[p] != e) sumCollected += dpW[e];
    if(sumCollected * 2 < Z[p] - 1) sumCollected++;
    dpW[p] = sumCollected;
  }

  // rep(i,N) cout << maxBlack[i] << " "; cout << endl;

  int ans = min(N, dpW[0] * 2 + 1);
  cout << ans << endl;
  return 0;
}




struct ios_do_not_sync {
    ios_do_not_sync() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0