結果

問題 No.1928 Make a Binary Tree
ユーザー harurunharurun
提出日時 2021-12-09 10:20:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 3,000 ms
コード長 1,232 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 109,880 KB
実行使用メモリ 22,428 KB
最終ジャッジ日時 2024-04-23 22:06:07
合計ジャッジ時間 12,218 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 11 ms
6,940 KB
testcase_16 AC 9 ms
6,944 KB
testcase_17 AC 6 ms
6,944 KB
testcase_18 AC 10 ms
6,944 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 7 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 8 ms
6,944 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 10 ms
6,944 KB
testcase_25 AC 12 ms
6,940 KB
testcase_26 AC 262 ms
18,408 KB
testcase_27 AC 151 ms
12,304 KB
testcase_28 AC 165 ms
12,868 KB
testcase_29 AC 306 ms
20,180 KB
testcase_30 AC 138 ms
11,712 KB
testcase_31 AC 194 ms
15,888 KB
testcase_32 AC 289 ms
19,724 KB
testcase_33 AC 157 ms
12,392 KB
testcase_34 AC 196 ms
15,976 KB
testcase_35 AC 231 ms
19,848 KB
testcase_36 AC 231 ms
21,776 KB
testcase_37 AC 198 ms
19,848 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 270 ms
20,468 KB
testcase_40 AC 265 ms
20,468 KB
testcase_41 AC 267 ms
20,344 KB
testcase_42 AC 269 ms
20,340 KB
testcase_43 AC 269 ms
20,512 KB
testcase_44 AC 272 ms
20,340 KB
testcase_45 AC 267 ms
20,592 KB
testcase_46 AC 273 ms
20,344 KB
testcase_47 AC 271 ms
20,340 KB
testcase_48 AC 269 ms
20,336 KB
testcase_49 AC 235 ms
20,868 KB
testcase_50 AC 316 ms
19,844 KB
testcase_51 AC 314 ms
19,976 KB
testcase_52 AC 318 ms
19,984 KB
testcase_53 AC 317 ms
19,976 KB
testcase_54 AC 318 ms
19,976 KB
testcase_55 AC 224 ms
21,120 KB
testcase_56 AC 327 ms
20,072 KB
testcase_57 AC 325 ms
20,192 KB
testcase_58 AC 325 ms
20,060 KB
testcase_59 AC 203 ms
22,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/segtree>
using namespace atcoder;

#include <iostream>
#include <vector>
#include <utility>
#include <deque>
using namespace std;

pair<int,int> op(pair<int,int> a,pair<int,int> b){
  return a>b?a:b;
}

pair<int,int> e(){
  return make_pair(-1,-1);
}
int main(){
  int N;
  cin>>N;
  vector<vector<int>> Graph(N);
  for(int i=0;i<N-1;i++){
    int x,y;
    cin>>x>>y;
    Graph[x-1].push_back(y-1);
    Graph[y-1].push_back(x-1);
  }
  segtree<pair<int,int>,op,e> seg(N);
  deque<int> que;
  que.push_back(N);
  que.push_back(0);
  vector<bool> checked(N,false);
  vector<int> pre(N);
  vector<int> cnt(N,1);
  int searched=0;
  while(!que.empty()){
    int q=que.back();que.pop_back();
    if(q<N){
      pre[q]=searched;
      checked[q]=true;
      for(int to:Graph[q]){
        if(!checked[to]){
          que.push_back(to+N);
          que.push_back(to);
        }
      }
    }else{
      for(int j=0;j<2;j++){
        pair<int,int> tmp=seg.prod(pre[q-N],searched);
        if(tmp.first==-1){
          break;
        }
        cnt[q-N]+=tmp.first;
        seg.set(tmp.second,e());
      }
      seg.set(searched,make_pair(cnt[q-N],searched));
      searched++;
    }
  }
  cout<<cnt[0]<<endl;
  return 0;
}
0