結果

問題 No.806 木を道に
ユーザー graythunder1graythunder1
提出日時 2019-06-26 20:33:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 952 bytes
コンパイル時間 1,223 ms
コンパイル使用メモリ 73,224 KB
実行使用メモリ 118,488 KB
最終ジャッジ日時 2023-09-08 08:11:29
合計ジャッジ時間 4,447 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

ll count(ll start, vector<vector<ll>> edges, ll* visited){
  visited[start] = 1;
  bool stop = true;
  ll cnt = 0;
  for(auto it = edges[start].begin(); it != edges[start].end(); ++it){
    if(!visited[*it]){
      cnt += count(*it, edges, visited);
      if(!stop) cnt++;
      stop = false;
    }
  }
  return cnt;
}

int main(){
  ll N;
  cin >> N;
  vector<vector<ll> > edges(N);
  rep(i, N-1){
    ll a, b;
    scanf("%lld %lld", &a, &b);
    edges[a-1].push_back(b-1);
    edges[b-1].push_back(a-1);
  }
  ll visited[N];
  rep(i, N) visited[i] = 0;

  ll start = 0;
  while(edges[start].size() != 1) start++;

  cout << count(start, edges, visited) << endl;
  return 0;
}
0