当前位置:网站首页>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;
}
边栏推荐
- [Yugong series] February 2022 U3D full stack class 005 unity engine view
- opencv之图像分割
- let const
- [Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
- iptables 之 state模块(ftp服务练习)
- POJ - 3616 Milking Time(DP+LIS)
- Leetcode 1984. Minimum difference in student scores
- Laravel8 uses passport login and JWT (generate token)
- AVL balanced binary search tree
- JEditableTable的使用技巧
猜你喜欢

2-3查找樹

Greenplum6.x搭建_安装

调用华为游戏多媒体服务的创建引擎接口返回错误码1002,错误信息:the params is error

Greenplum 6.x build_ Environment configuration

iptables 之 state模块(ftp服务练习)

【踩坑】nacos注册一直连接localhost:8848,no available server

Count sort (diagram)

Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error

IP地址的类别

JS operation
随机推荐
2-3查找樹
POJ - 3616 Milking Time(DP+LIS)
Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
Iptables' state module (FTP service exercise)
Through the "last mile" of legal services for the masses, fangzheng Puhua labor and personnel law self-service consulting service platform has been frequently "praised"
How to add a mask of a target in a picture
如何在快应用中实现滑动操作组件
[hard core science popularization] working principle of dynamic loop monitoring system
ES6_ Arrow function
指针进阶,字符串函数
Virtual address space
How to realize the high temperature alarm of the machine room in the moving ring monitoring system
2-3查找树
Sign and authenticate API interface or H5 interface
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
路由信息协议——RIP
[Yugong series] February 2022 U3D full stack class 006 unity toolbar
What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
Rapid integration of authentication services - harmonyos platform