結果

問題 No.763 Noelちゃんと木遊び
ユーザー khora0301khora0301
提出日時 2021-12-23 15:38:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 80,132 KB
実行使用メモリ 19,708 KB
最終ジャッジ日時 2023-10-17 16:39:52
合計ジャッジ時間 3,413 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
19,708 KB
testcase_01 AC 28 ms
5,188 KB
testcase_02 AC 70 ms
7,564 KB
testcase_03 AC 46 ms
6,244 KB
testcase_04 AC 33 ms
5,452 KB
testcase_05 AC 43 ms
6,244 KB
testcase_06 AC 85 ms
8,620 KB
testcase_07 AC 85 ms
8,356 KB
testcase_08 AC 49 ms
6,508 KB
testcase_09 AC 31 ms
5,452 KB
testcase_10 AC 13 ms
4,348 KB
testcase_11 AC 87 ms
8,620 KB
testcase_12 AC 75 ms
8,092 KB
testcase_13 AC 74 ms
8,092 KB
testcase_14 AC 63 ms
7,564 KB
testcase_15 AC 43 ms
6,244 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 44 ms
6,244 KB
testcase_18 AC 86 ms
8,620 KB
testcase_19 AC 77 ms
8,092 KB
testcase_20 AC 80 ms
8,092 KB
権限があれば一括ダウンロードができます

ソースコード

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