結果

問題 No.806 木を道に
コンテスト
ユーザー sawfish
提出日時 2022-10-24 11:00:29
言語 C++17(clang)
(clang++ 21.1.8 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 451 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,111 ms
コンパイル使用メモリ 138,368 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2026-03-23 22:19:38
合計ジャッジ時間 3,260 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:13:19: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   13 |     vector<int> G[N + 1];
      |                   ^~~~~
main.cpp:13:19: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:10:9: note: declared here
   10 |     int N;
      |         ^
1 warning generated.

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <map>

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int N;
    cin >> N;

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

    map<int, int> D;
    for (int i = 1; i <= N; i++) {
        D[G[i].size()]++;
    }

    cout << D[1] - 2 << endl;
}
0