結果

問題 No.806 木を道に
ユーザー niuezniuez
提出日時 2019-03-22 21:41:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 165,472 KB
実行使用メモリ 10,088 KB
最終ジャッジ日時 2023-10-19 06:51:01
合計ジャッジ時間 4,167 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 18 ms
4,732 KB
testcase_11 AC 16 ms
4,468 KB
testcase_12 AC 76 ms
8,692 KB
testcase_13 AC 53 ms
7,372 KB
testcase_14 AC 71 ms
8,428 KB
testcase_15 AC 78 ms
8,956 KB
testcase_16 AC 26 ms
5,260 KB
testcase_17 AC 67 ms
8,164 KB
testcase_18 AC 7 ms
4,348 KB
testcase_19 AC 19 ms
4,732 KB
testcase_20 AC 66 ms
8,164 KB
testcase_21 AC 36 ms
6,052 KB
testcase_22 AC 92 ms
9,748 KB
testcase_23 AC 90 ms
9,748 KB
testcase_24 AC 38 ms
6,588 KB
testcase_25 AC 57 ms
8,428 KB
testcase_26 AC 20 ms
5,276 KB
testcase_27 AC 66 ms
10,088 KB
testcase_28 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

vector<vector<int>> g;

int main() {
  int N;
  cin >> N;
  g.resize(N);
  vector<int> cnt(N);
  vector<int> a(N - 1), b(N - 1);
  for(int i = 0;i < N - 1;i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
    cnt[a[i]]++;
    cnt[b[i]]++;
  }

  i64 ans = 0;

  for(int i = 0;i < N;i++) {
    if(cnt[i] >= 2) {
      ans += cnt[i] - 2;
    }
  }
  cout << ans << endl;
}
0