結果
問題 |
No.2427 Tree Distance Two
|
ユーザー |
![]() |
提出日時 | 2023-08-22 14:58:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 258 ms / 2,000 ms |
コード長 | 619 bytes |
コンパイル時間 | 2,033 ms |
コンパイル使用メモリ | 196,776 KB |
最終ジャッジ日時 | 2025-02-16 12:16:20 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; vector<int> G[300300]; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; rep(i,n-1){ int u,v; cin>>u>>v; u--,v--; G[u].push_back(v); G[v].push_back(u); } vector<int> ANS(n); auto dfs=[&](auto dfs,int v,int p)->void{ for(auto nv:G[v]){ ANS[nv]+=(int)G[v].size()-1; if(nv==p) continue; dfs(dfs,nv,v); } }; dfs(dfs,0,-1); rep(i,n) cout<<ANS[i]<<'\n'; return 0; }