結果

問題 No.2427 Tree Distance Two
ユーザー twooimptwooimp
提出日時 2023-08-18 21:47:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 693 ms / 2,000 ms
コード長 514 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 171,600 KB
実行使用メモリ 30,408 KB
最終ジャッジ日時 2024-05-06 03:45:15
合計ジャッジ時間 13,643 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 640 ms
23,808 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 667 ms
23,808 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 589 ms
30,408 KB
testcase_08 AC 587 ms
26,496 KB
testcase_09 AC 581 ms
24,832 KB
testcase_10 AC 597 ms
24,960 KB
testcase_11 AC 591 ms
30,224 KB
testcase_12 AC 693 ms
27,020 KB
testcase_13 AC 655 ms
26,912 KB
testcase_14 AC 604 ms
22,016 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 17 ms
5,376 KB
testcase_21 AC 20 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 18 ms
5,376 KB
testcase_25 AC 169 ms
8,576 KB
testcase_26 AC 383 ms
16,000 KB
testcase_27 AC 260 ms
12,416 KB
testcase_28 AC 591 ms
22,272 KB
testcase_29 AC 505 ms
19,968 KB
testcase_30 AC 390 ms
15,616 KB
testcase_31 AC 247 ms
11,264 KB
testcase_32 AC 405 ms
15,488 KB
testcase_33 AC 323 ms
14,208 KB
testcase_34 AC 96 ms
6,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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);
  }
  vector<ll> v(n,0);
  for(ll i=0;i<n;i++){
    ll sz=G[i].size();
    if(sz>1){
      vector<ll> used;
      for(ll u:G[i]){
        used.push_back(u);
      }
      for(ll u:used){
        v[u]+=sz-1;
      }
    }
  }
  for(ll i=0;i<n;i++){
    cout<<v[i]<<endl;
  }
}
0