結果

問題 No.806 木を道に
ユーザー seriru13seriru13
提出日時 2019-07-28 12:41:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 113,996 KB
実行使用メモリ 12,284 KB
最終ジャッジ日時 2023-09-15 11:27:37
合計ジャッジ時間 3,176 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,388 KB
testcase_10 AC 17 ms
4,380 KB
testcase_11 AC 15 ms
4,380 KB
testcase_12 AC 72 ms
7,692 KB
testcase_13 AC 50 ms
6,392 KB
testcase_14 AC 70 ms
7,592 KB
testcase_15 AC 74 ms
8,004 KB
testcase_16 AC 24 ms
4,632 KB
testcase_17 AC 62 ms
7,260 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 18 ms
4,380 KB
testcase_20 AC 60 ms
7,184 KB
testcase_21 AC 35 ms
5,428 KB
testcase_22 AC 88 ms
8,500 KB
testcase_23 AC 87 ms
8,596 KB
testcase_24 AC 38 ms
9,180 KB
testcase_25 AC 57 ms
12,284 KB
testcase_26 AC 19 ms
4,872 KB
testcase_27 AC 62 ms
8,820 KB
testcase_28 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int total;

void dfs(vector<vector<int>> const& g, int from, int now, int invRank) {
  int trank = invRank + 1;
  total += max<ll>(g[now].size() - 2, 0);
  for (auto&& itr : g[now]) {
    if (itr != from) {
      dfs(g, now, itr, trank);
    }
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  dfs(g, -1, 0, 0);
  cout << total << endl;
}
0