結果

問題 No.806 木を道に
ユーザー tnakao0123tnakao0123
提出日時 2019-03-24 22:01:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 887 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 88,040 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-15 04:15:51
合計ジャッジ時間 2,402 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 31 ms
8,448 KB
testcase_13 AC 21 ms
8,056 KB
testcase_14 AC 28 ms
8,448 KB
testcase_15 AC 28 ms
8,704 KB
testcase_16 AC 12 ms
6,984 KB
testcase_17 AC 25 ms
8,192 KB
testcase_18 AC 5 ms
6,944 KB
testcase_19 AC 9 ms
6,944 KB
testcase_20 AC 25 ms
8,232 KB
testcase_21 AC 15 ms
7,296 KB
testcase_22 AC 35 ms
9,088 KB
testcase_23 AC 34 ms
9,088 KB
testcase_24 AC 16 ms
7,552 KB
testcase_25 AC 23 ms
8,320 KB
testcase_26 AC 11 ms
6,944 KB
testcase_27 AC 26 ms
8,952 KB
testcase_28 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:49:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |     scanf("%d%d", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 806.cc:  No.806 木を道に - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    nbrs[a].push_back(b);
    nbrs[b].push_back(a);
  }

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (nbrs[i].size() > 2) cnt += nbrs[i].size() - 2;
  printf("%d\n", cnt);
  return 0;
}
0