結果

問題 No.806 木を道に
ユーザー TiramisterTiramister
提出日時 2019-03-22 22:51:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 73,900 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-10-19 10:03:06
合計ジャッジ時間 2,761 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 2 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 19 ms
4,632 KB
testcase_11 AC 17 ms
4,632 KB
testcase_12 AC 77 ms
8,856 KB
testcase_13 AC 55 ms
7,272 KB
testcase_14 AC 74 ms
8,592 KB
testcase_15 AC 77 ms
8,856 KB
testcase_16 AC 27 ms
5,424 KB
testcase_17 AC 67 ms
8,064 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 AC 19 ms
4,896 KB
testcase_20 AC 67 ms
8,064 KB
testcase_21 AC 37 ms
5,952 KB
testcase_22 AC 90 ms
9,648 KB
testcase_23 AC 93 ms
9,648 KB
testcase_24 AC 39 ms
6,216 KB
testcase_25 AC 58 ms
7,800 KB
testcase_26 AC 22 ms
5,648 KB
testcase_27 AC 70 ms
10,932 KB
testcase_28 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

template <class T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from = -1, int to = -1, T cost = 1) : from(from), to(to), cost(cost){};

    bool operator<(const Edge<T>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<T>& e) const { return this->cost > e.cost; }
};

template <class T = int>
class Graph {
public:
    explicit Graph(int N = 0) : size(N) { path.resize(size); }
    void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(u, v, cost)); }
    std::vector<Edge<T>> operator[](int v) const { return path[v]; }

    int size;
    std::vector<std::vector<Edge<T>>> path;
};

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

    Graph<> tree(N);
    for (int i = 0; i < N - 1; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        tree.span(u, v);
        tree.span(v, u);
    }

    int ans = 0;
    for (int v = 0; v < N; ++v) {
        ans += std::max(0, (int)tree[v].size() - 2);
    }
    std::cout << ans << std::endl;
    return 0;
}
0