結果

問題 No.806 木を道に
ユーザー chocopuuchocopuu
提出日時 2019-03-22 21:42:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,364 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 170,004 KB
実行使用メモリ 13,000 KB
最終ジャッジ日時 2023-10-19 06:51:54
合計ジャッジ時間 3,410 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,752 KB
testcase_01 AC 4 ms
6,752 KB
testcase_02 AC 3 ms
6,756 KB
testcase_03 AC 3 ms
6,756 KB
testcase_04 AC 4 ms
6,756 KB
testcase_05 AC 4 ms
6,760 KB
testcase_06 AC 4 ms
6,760 KB
testcase_07 AC 4 ms
6,756 KB
testcase_08 AC 3 ms
6,752 KB
testcase_09 AC 4 ms
6,756 KB
testcase_10 AC 12 ms
7,576 KB
testcase_11 AC 11 ms
7,488 KB
testcase_12 AC 51 ms
9,896 KB
testcase_13 AC 32 ms
9,032 KB
testcase_14 AC 45 ms
9,740 KB
testcase_15 AC 55 ms
9,928 KB
testcase_16 AC 17 ms
7,900 KB
testcase_17 AC 44 ms
9,508 KB
testcase_18 AC 7 ms
7,064 KB
testcase_19 AC 13 ms
7,616 KB
testcase_20 AC 42 ms
9,492 KB
testcase_21 AC 22 ms
8,308 KB
testcase_22 AC 61 ms
10,452 KB
testcase_23 AC 62 ms
10,452 KB
testcase_24 AC 21 ms
10,872 KB
testcase_25 AC 31 ms
13,000 KB
testcase_26 AC 11 ms
7,692 KB
testcase_27 AC 28 ms
10,232 KB
testcase_28 AC 4 ms
6,868 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:57:8: warning: 'ma' may be used uninitialized [-Wmaybe-uninitialized]
   57 |     dfs(ma,-1);
      |     ~~~^~~~~~~
main.cpp:48:14: note: 'ma' was declared here
   48 |     int t=-1,ma;
      |              ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define FOR(i,n) for(int i = 0;i<n;i++)
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1ll<<60;
typedef vector<vint>vvint;

int N;
vint g[100010];
int dist[100010];
int cnt=0;

void dfs(int now,int par){
    if(g[now].size()==1)cnt++;
    for(auto e:g[now]){
        if(e==par)continue;
        dist[e]=dist[now]+1;
        dfs(e,now);
    }
}

signed main() {
    IOS();
    cin>>N;
    rep(i,0,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    
    dfs(0,-1);
    int t=-1,ma;
    rep(i,0,N){
        if(t<dist[i]){
            t=dist[i];
            ma=i;
        }
    }
    rep(i,0,100010)dist[i]=0;
    cnt=0;
    dfs(ma,-1);
    cout<<cnt-2<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}
0