update
This commit is contained in:
parent
5547203c8d
commit
ed231e6777
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,4 +4,5 @@ build
|
||||
*.json
|
||||
/cmake-build*
|
||||
/build*
|
||||
/test*.txt
|
||||
/test*.txt
|
||||
/out
|
40
src/P1395/P1395.cpp
Normal file
40
src/P1395/P1395.cpp
Normal 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';
|
||||
}
|
Loading…
Reference in New Issue
Block a user