結果

問題 No.806 木を道に
ユーザー polyomino_24polyomino_24
提出日時 2019-03-22 23:48:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,624 bytes
コンパイル時間 990 ms
コンパイル使用メモリ 103,180 KB
実行使用メモリ 17,252 KB
最終ジャッジ日時 2023-10-19 10:57:57
合計ジャッジ時間 3,175 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,008 KB
testcase_01 AC 4 ms
6,008 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 4 ms
6,012 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
6,012 KB
testcase_08 AC 3 ms
6,008 KB
testcase_09 AC 3 ms
6,012 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 46 ms
13,420 KB
testcase_25 AC 68 ms
17,252 KB
testcase_26 AC 23 ms
7,068 KB
testcase_27 AC 69 ms
9,844 KB
testcase_28 AC 5 ms
6,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
vector<int>g[100005];
int ans;
int dfs(int s,int p){
//    show(s);
    int temp = 0;
    vector<int>a;
    for(int x:g[s]){
        if(x == p)continue;
        a.push_back(dfs(x,s));
    }
    sort(a.rbegin(),a.rend());
    if(a.size()>1)ans = max(ans,a[0]+a[1]+2);
    if(a.size()){
        ans = max(ans, a[0] + 1);
        temp = max(temp, a[0] + 1);
    }
    return temp;
}
int main(){
    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);
    }
    dfs(0,-1);
    cout << n-1-ans << endl;
}
0