結果

問題 No.763 Noelちゃんと木遊び
ユーザー miwawamiwawa
提出日時 2024-02-23 14:09:52
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 93,792 KB
実行使用メモリ 16,896 KB
最終ジャッジ日時 2024-02-23 14:09:57
合計ジャッジ時間 4,291 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
16,896 KB
testcase_01 AC 30 ms
6,676 KB
testcase_02 AC 75 ms
7,936 KB
testcase_03 AC 48 ms
6,676 KB
testcase_04 AC 33 ms
6,676 KB
testcase_05 AC 45 ms
6,676 KB
testcase_06 AC 88 ms
8,832 KB
testcase_07 AC 87 ms
8,704 KB
testcase_08 AC 51 ms
6,676 KB
testcase_09 AC 32 ms
6,676 KB
testcase_10 AC 13 ms
6,676 KB
testcase_11 AC 92 ms
8,960 KB
testcase_12 AC 81 ms
8,320 KB
testcase_13 AC 78 ms
8,320 KB
testcase_14 AC 68 ms
7,808 KB
testcase_15 AC 46 ms
6,676 KB
testcase_16 AC 9 ms
6,676 KB
testcase_17 AC 46 ms
6,676 KB
testcase_18 AC 89 ms
8,832 KB
testcase_19 AC 80 ms
8,448 KB
testcase_20 AC 89 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define rep(i,a,b) for(i=a;i<b;i++)
using namespace std;
using Graph = vector<vector<int>>;
  vector<int> a[100001];
  vector<bool> tomato;
void f(int v,int p){
  bool topi=false;
  for(auto ch:a[v]){
    if(ch==p)continue;
    f(ch,v);
    if(tomato[ch])topi=true;
  }
  if(!topi)tomato[v]=true;
}

int main() {
  int n,aa,b,i;
  cin>>n;

  rep(i,0,n-1){
    cin>>aa>>b;
    a[aa].push_back(b);
    a[b].push_back(aa);
  }
  tomato.assign(n,false);
  f(1,0);
  int h=0;
  rep(i,0,n+1){
    if(tomato[i])h++;
  }
  cout<<h<<endl;
}
0