結果

問題 No.1098 LCAs
ユーザー SmitMangukiyaSmitMangukiya
提出日時 2020-06-26 22:36:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 1,116 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 167,288 KB
実行使用メモリ 29,068 KB
最終ジャッジ日時 2023-09-18 06:05:56
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,108 KB
testcase_01 AC 4 ms
9,196 KB
testcase_02 AC 4 ms
9,112 KB
testcase_03 AC 5 ms
9,116 KB
testcase_04 AC 5 ms
9,168 KB
testcase_05 AC 5 ms
9,204 KB
testcase_06 AC 4 ms
9,116 KB
testcase_07 AC 4 ms
9,108 KB
testcase_08 AC 4 ms
9,112 KB
testcase_09 AC 5 ms
9,148 KB
testcase_10 AC 4 ms
9,200 KB
testcase_11 AC 5 ms
9,152 KB
testcase_12 AC 4 ms
9,200 KB
testcase_13 AC 4 ms
9,172 KB
testcase_14 AC 4 ms
9,404 KB
testcase_15 AC 5 ms
9,172 KB
testcase_16 AC 4 ms
9,256 KB
testcase_17 AC 5 ms
9,180 KB
testcase_18 AC 168 ms
18,660 KB
testcase_19 AC 167 ms
18,708 KB
testcase_20 AC 163 ms
18,660 KB
testcase_21 AC 164 ms
18,928 KB
testcase_22 AC 162 ms
18,724 KB
testcase_23 AC 107 ms
18,552 KB
testcase_24 AC 110 ms
18,552 KB
testcase_25 AC 102 ms
18,664 KB
testcase_26 AC 108 ms
18,612 KB
testcase_27 AC 106 ms
18,500 KB
testcase_28 AC 198 ms
28,120 KB
testcase_29 AC 194 ms
29,068 KB
testcase_30 AC 191 ms
28,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const int N =2e5 + 5;
vi g[N];
int dp[N];
int ans[N];

void dfs(int node , int p){
   dp[node] = 1;
   for(int u : g[node]){
      if(u != p){
         dfs(u , node);
         dp[node] += dp[u];
      }
   }

   ans[node] = dp[node];
   for(int u : g[node]){
      if(u != p){
         ans[node] += dp[u] * (dp[node] - dp[u]);
      }
   }
}
int32_t main(){
   fast;
   int n;
   cin >> n;

   f(i,0,n-1){
      int u,v;
      cin >> u >> v;
      g[u].pb(v);
      g[v].pb(u);
   }

   dfs(1,0);
   f(i,1,n+1)  cout << ans[i] << "\n";

}
0