当前位置:网站首页>Mountaineering team (DFS)
Mountaineering team (DFS)
2022-07-07 08:48:00 【why151】
Title Description :

Main idea :
I didn't see this topic clearly at first , I think everyone can choose a way to climb up .
Later, it was found that there was a person on each road , Then I have no idea .
Because I don't know how to judge that road, facing the problem of passing two people at the same time .
Then I saw dalao Code for , Or reverse from 1 Start , Each time, one person goes up from the next node on each road , I think it's wonderful !
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int num[1010];
vector<int> l[1010];
int f[1010];// Record how many people there are at each point
// One person on each node takes a step up to the next node
void dfs(int x,int last)
{
for(int i=0;i<l[x].size();i++)
{
int nowx=l[x][i];
if(nowx!=last)
{
if(f[nowx])
{
f[nowx]-=1;
f[x]+=1;
}
dfs(nowx,x);
}
}
}
int main()
{
int n;
cin>>n;
for(int i=1;i<n;i++)
{
int x,y;
cin>>x>>y;
l[x].push_back(y);
l[y].push_back(x);
num[x]+=1;
num[y]+=1;
}
int sum=0;
for(int i=2;i<=n;i++)
{
if(num[i]==1) f[i]=1,sum+=1;
}
int ans=0;
while(f[1]!=sum)
{
dfs(1,0);
ans+=1;
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- Mock.js用法详解
- Category of IP address
- Novice entry SCM must understand those things
- 【踩坑】nacos注册一直连接localhost:8848,no available server
- Golan idea IntelliJ cannot input Chinese characters
- Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
- 2-3查找树
- MySQL partition explanation and operation statement
- SSM integration
- Laravel8 uses passport login and JWT (generate token)
猜你喜欢

xray的简单使用

Greenplum6.x常用语句

Componentspace2022, assertions, protocols, bindings, and configuration files

oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量

Teach you how to select PCB board by hand (II)

指针进阶,字符串函数

A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)

Introduction to data fragmentation

Go语言中,函数是一种类型

Virtual address space
随机推荐
Quick sorting (detailed illustration of single way, double way, three way)
Three usage scenarios of annotation @configurationproperties
Database storage - table partition
[Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
对API接口或H5接口做签名认证
Greenplum6.x-版本变化记录-常用手册
[wechat applet: cache operation]
国标GB28181协议视频平台EasyGBS新增拉流超时配置
如何在快应用中实现滑动操作组件
23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
【踩坑】nacos注册一直连接localhost:8848,no available server
POJ - 3616 Milking Time(DP+LIS)
Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
Arm GIC (IV) GIC V3 register class analysis notes.
2-3查找樹
How to understand distributed architecture and micro service architecture
opencv之图像分割
IP地址的类别
[Nanjing University] - [software analysis] course learning notes (I) -introduction
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error