結果
| 問題 |
No.806 木を道に
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2019-03-24 22:01:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 887 bytes |
| コンパイル時間 | 877 ms |
| コンパイル使用メモリ | 88,132 KB |
| 実行使用メモリ | 9,088 KB |
| 最終ジャッジ日時 | 2024-10-04 15:12:41 |
| 合計ジャッジ時間 | 3,046 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- 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;
}
tnakao0123