結果

問題 No.806 木を道に
ユーザー betrue12betrue12
提出日時 2019-03-22 21:45:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 350 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 193,564 KB
最終ジャッジ日時 2025-01-06 23:47:53
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

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

int main(){
    int N;
    cin >> N;
    int deg[100000] = {0};
    for(int i=0; i<N-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        deg[a-1]++;
        deg[b-1]++;
    }

    int leaf = 0;
    for(int i=0; i<N; i++) if(deg[i] == 1) leaf++;
    cout << leaf-2 << endl;
    return 0;
}
0