結果

問題 No.763 Noelちゃんと木遊び
ユーザー khora0301khora0301
提出日時 2021-12-23 15:35:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 763 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 814,908 KB
最終ジャッジ日時 2023-10-17 16:37:31
合計ジャッジ時間 5,845 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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