結果

問題 No.806 木を道に
ユーザー sansaquasansaqua
提出日時 2019-08-06 00:23:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 72,588 KB
実行使用メモリ 9,132 KB
最終ジャッジ日時 2023-09-25 17:36:30
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 32 ms
8,244 KB
testcase_13 AC 23 ms
6,684 KB
testcase_14 AC 30 ms
7,720 KB
testcase_15 AC 31 ms
8,412 KB
testcase_16 AC 12 ms
4,808 KB
testcase_17 AC 27 ms
7,676 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 28 ms
7,560 KB
testcase_21 AC 16 ms
5,828 KB
testcase_22 AC 37 ms
9,032 KB
testcase_23 AC 37 ms
9,076 KB
testcase_24 AC 17 ms
5,872 KB
testcase_25 AC 25 ms
7,512 KB
testcase_26 AC 10 ms
4,988 KB
testcase_27 AC 28 ms
9,132 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>

using namespace std;
using ll = long long int;

#define PREPARED_ENVIRONMENT

template <class T> std::ostream& operator<<(std::ostream& o, const std::vector<T>& v) {
  o << "{";
  for (int i = 0; i < (int) v.size(); i++)
    o << (i > 0 ? ", " : "" ) << v[i];
  o << "}";
  return o;
}

template <class X, class Y> std::ostream& operator<<(std::ostream& o, const std::pair<X, Y>& p) {
  o << "(" << p.first << ", " << p.second << ")";
  return o;
}

ll n;
ll ans = 0;
vector<vector<ll>> graph;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  graph = vector<vector<ll>>(n);
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    ans += max(0, (int) (graph[i].size())-2);
  }
  cout << ans << endl;
  return 0;
}
0