結果

問題 No.1098 LCAs
ユーザー NewGardenNewGarden
提出日時 2020-06-26 21:57:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,008 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 170,216 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 04:25:25
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=10;
const ll mod=1e9+7;


vector<int> v[mx];
vector<int> ne(mx);
vector<ll> cnt(mx,0);


ll dfs(int x, int p){
  ll tmp = 0;
  ne[x] = p;
  for(auto to:v[x]){
    if(to==p) continue;
    tmp += dfs(to,x) + 1;
  }
  return cnt[x] = tmp;
}

int main(){
  int n;
  cin >> n;
  rep(i,n-1){
    int x,y; cin >> x >> y; x--; y--;
    v[x].emplace_back(y);
    v[y].emplace_back(x);
  }
  dfs(0,-1);
  rep(i,n){
    vector<ll> a;
    ll sum = 0;
    for(auto to:v[i]){
      if(to==ne[i]) continue;
      a.emplace_back(cnt[to]+1);
      sum += cnt[to]+1;
    }
    ll ans = 1;
    for(auto it:a){
      ans += it*(sum-it);
    }
    ans += sum*2;
    cout << ans << ln;
  }
  return 0;
}
0