結果

問題 No.763 Noelちゃんと木遊び
ユーザー planesplanes
提出日時 2023-03-08 17:25:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 175,756 KB
実行使用メモリ 14,960 KB
最終ジャッジ日時 2023-10-18 05:58:21
合計ジャッジ時間 4,531 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
14,960 KB
testcase_01 AC 29 ms
5,456 KB
testcase_02 AC 76 ms
8,096 KB
testcase_03 AC 49 ms
6,512 KB
testcase_04 AC 33 ms
5,720 KB
testcase_05 AC 46 ms
6,512 KB
testcase_06 AC 95 ms
9,152 KB
testcase_07 AC 89 ms
8,888 KB
testcase_08 AC 51 ms
6,776 KB
testcase_09 AC 32 ms
5,720 KB
testcase_10 AC 12 ms
4,348 KB
testcase_11 AC 91 ms
9,152 KB
testcase_12 AC 79 ms
8,624 KB
testcase_13 AC 80 ms
8,360 KB
testcase_14 AC 70 ms
7,832 KB
testcase_15 AC 44 ms
6,512 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 47 ms
6,512 KB
testcase_18 AC 91 ms
9,152 KB
testcase_19 AC 83 ms
8,624 KB
testcase_20 AC 84 ms
8,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

vector<vector<ll>> vec;
vector<bool> note;

ll ans=0;

void solve(ll k,ll from) {

ll count=0;

  for(auto x:vec[k]) {
    if(x==from) continue;
    solve(x,k);
    if(!note[x]) count++;
  }

  if(count>0) {
    ans+=count;
    note[k]=true;
  }
  return ;
}



int main() {
   ll N;cin>>N;
vec=vector<vector<ll>> (N,vector<ll> (0));
note=vector<bool> (N,false);

for(ll i=0;i<N-1;i++) {
  ll U,V;cin>>U>>V;
  U--;V--;
  vec[U].push_back(V);
  vec[V].push_back(U);
}

solve(0,0);
if(!note[0]) ans++;

cout<<ans<<endl;
}




0