結果

問題 No.2427 Tree Distance Two
ユーザー twooimptwooimp
提出日時 2023-08-18 21:28:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 590 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 171,728 KB
実行使用メモリ 33,808 KB
最終ジャッジ日時 2024-05-06 03:18:55
合計ジャッジ時間 7,395 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 811 ms
21,632 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 844 ms
21,504 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

void dfs(ll now,ll pre,ll cnt,vector<vector<ll>> &G,vector<ll> &v){
  if(cnt==2){
    v.push_back(now);
    return;
  }
  for(ll next:G[now]){
    if(next!=pre){
      dfs(next,now,cnt+1,G,v);
    }
  }
}

int main(){
  ll n;
  cin>>n;
  vector<vector<ll>> G(n);
  for(ll i=0;i<n-1;i++){
    ll u,v;
    cin>>u>>v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for(ll i=0;i<n;i++){
    vector<ll> v;
    dfs(i,-1,0,G,v);
    v.erase(unique(v.begin(),v.end()),v.end());
    cout<<v.size()<<endl;
  }
}
0