This commit is contained in:
Zengtudor 2024-11-14 09:34:09 +08:00
parent 5547203c8d
commit ed231e6777
2 changed files with 42 additions and 1 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ build
*.json
/cmake-build*
/build*
/test*.txt
/test*.txt
/out

40
src/P1395/P1395.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <cstdint>
#include <iostream>
#include <vector>
using ll = int64_t;
using vl = std::vector<ll>;
auto &ci = std::cin;
auto &co = std::cout;
const ll max_n = 5e4+5;
ll *sn = new ll[max_n];
auto *nds = new vl[max_n];
void dfs(ll ft, ll n){
if(nds[n].size()<=1){
return;
}
sn[n]=1;
for(ll i:nds[n]){
if(i==ft){
continue;
}
dfs(n, i);
sn[n]+=sn[i];
}
return;
}
int main(){
ll n;
ci>>n;
for(ll i{1}; i<n; i++){
ll a, b;
ci>>a>>b;
nds[a].push_back(b);
nds[b].push_back(a);
}
for(ll i{1};i<=n;i++)co<<sn[i]<<' ';
co<<'\n';
}