結果

問題 No.806 木を道に
ユーザー uchiiiiuchiiii
提出日時 2020-08-10 17:17:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 3,046 ms
コンパイル使用メモリ 221,956 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-27 03:19:35
合計ジャッジ時間 4,521 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 11 ms
6,940 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 35 ms
8,448 KB
testcase_13 AC 25 ms
7,680 KB
testcase_14 AC 33 ms
8,320 KB
testcase_15 AC 37 ms
8,556 KB
testcase_16 AC 15 ms
6,940 KB
testcase_17 AC 31 ms
8,064 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 11 ms
6,940 KB
testcase_20 AC 30 ms
8,136 KB
testcase_21 AC 17 ms
7,020 KB
testcase_22 AC 41 ms
9,088 KB
testcase_23 AC 44 ms
8,960 KB
testcase_24 AC 21 ms
10,624 KB
testcase_25 AC 28 ms
13,184 KB
testcase_26 AC 11 ms
6,940 KB
testcase_27 AC 29 ms
9,080 KB
testcase_28 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:7:14: warning: 'start' may be used uninitialized [-Wmaybe-uninitialized]
    7 | #define endl "\n"
      |              ^~~~
main.cpp:40:9: note: 'start' was declared here
   40 |     int start;
      |         ^~~~~

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
//-------------------
constexpr int MX = 1e5+4;
vector<int> G[MX];
vector<bool> visited(MX, false);

int dfs(int node) {
    visited[node] = true;
    if(G[node].size() == 1) return 0;
    int cnt = G[node].size() - 2;
    for(auto &e: G[node]) {
        if(!visited[e]) cnt += dfs(e);
    }
    return cnt;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    int n; cin >> n;
    rep(i,n-1) {
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int start;
    rep(i,n) {
        if(G[i].size() > 1) {
            start = i;
            break;
        }
    }
    cout << dfs(start) << endl;
    return 0;
}
0