結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 8 ms
4,532 KB
testcase_12 AC 32 ms
8,060 KB
testcase_13 AC 24 ms
6,660 KB
testcase_14 AC 31 ms
7,740 KB
testcase_15 AC 35 ms
8,288 KB
testcase_16 AC 12 ms
4,872 KB
testcase_17 AC 28 ms
7,464 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 AC 29 ms
7,448 KB
testcase_21 AC 17 ms
5,660 KB
testcase_22 AC 39 ms
9,108 KB
testcase_23 AC 37 ms
9,140 KB
testcase_24 AC 17 ms
5,864 KB
testcase_25 AC 24 ms
7,564 KB
testcase_26 AC 10 ms
4,860 KB
testcase_27 AC 26 ms
9,028 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 << "\n";
  return 0;
}
0