結果
| 問題 |
No.1098 LCAs
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-26 21:49:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 498 ms / 2,000 ms |
| コード長 | 474 bytes |
| コンパイル時間 | 594 ms |
| コンパイル使用メモリ | 72,320 KB |
| 実行使用メモリ | 40,704 KB |
| 最終ジャッジ日時 | 2024-07-04 20:39:16 |
| 合計ジャッジ時間 | 7,703 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
24 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
using namespace std;
int N;
vector<int>G[2<<17];
long ans[2<<17];
long dfs(int u,int p)
{
long c=1;
vector<long>now;
for(int v:G[u])if(v!=p)
{
long t=dfs(v,u);
now.push_back(t);
c+=t;
}
ans[u]=c;
for(long x:now)
{
ans[u]+=(c-x)*x;
}
return c;
}
main()
{
cin>>N;
for(int i=1;i<N;i++)
{
int u,v;cin>>u>>v;
u--,v--;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(0,-1);
for(int i=0;i<N;i++)cout<<ans[i]<<endl;
}