結果

問題 No.763 Noelちゃんと木遊び
ユーザー khora0301
提出日時 2021-12-23 15:38:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 76,212 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2025-03-22 10:40:28
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<bool> visited;
vector<bool> used;
void dfs(vector<vector<int> > &graph, int i){
    visited[i] = true;
    bool used_flg = true;
    for (int j : graph[i]){
        if (visited[j]) continue;
        dfs(graph, j) ;
        if (used[j]) used_flg=false; 
    }
    used[i] = used_flg;
}


int main()
{
  int N;
  cin >> N;
  vector<vector<int> > graph(N);

  for (int i = 1; i < N; i++)
  {
    int a, b;
    cin >> a >> b;

    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }
    
  used.assign(N, false);
  visited.assign(N, false);    
  dfs(graph,0);
  int ans = 0;
  for (auto i:used){
      if (i) ans++;
  }
  
  cout << ans << endl;

  return 0;
}
0