結果
問題 | No.806 木を道に |
ユーザー | tottoripaper |
提出日時 | 2019-03-22 21:36:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 971 bytes |
コンパイル時間 | 1,679 ms |
コンパイル使用メモリ | 169,624 KB |
実行使用メモリ | 13,800 KB |
最終ジャッジ日時 | 2023-10-19 06:35:29 |
合計ジャッジ時間 | 3,451 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,300 KB |
testcase_01 | AC | 4 ms
6,300 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 3 ms
6,304 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 3 ms
6,304 KB |
testcase_08 | AC | 3 ms
6,300 KB |
testcase_09 | AC | 3 ms
6,304 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 23 ms
11,244 KB |
testcase_25 | AC | 33 ms
13,800 KB |
testcase_26 | AC | 11 ms
7,240 KB |
testcase_27 | AC | 29 ms
9,364 KB |
testcase_28 | AC | 4 ms
6,408 KB |
ソースコード
#include <bits/stdc++.h> #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = std::int64_t; using P = std::tuple<int,int>; int N; std::vector<int> G[100100]; int d[100100]; void dfs(int v, int p, int c){ d[v] = c; for(int w : G[v]){ if(w == p){ continue; } if(d[w] == -1){ dfs(w, v, c + 1); } } } int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N; for(int i=0;i<N-1;++i){ int a, b; std::cin >> a >> b; G[a].emplace_back(b); G[b].emplace_back(a); } memset(d, -1, sizeof(d)); dfs(1, -1, 0); int v = std::max_element(d + 1, d + 1 + N) - d; memset(d, -1, sizeof(d)); dfs(v, -1, 0); int mn = (N - 1) - *std::max_element(d + 1, d + 1 + N); std::cout << mn << std::endl; }