当前位置:网站首页>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;
}
边栏推荐
- 路由信息协议——RIP
- 如何在HarmonyOS应用中集成App Linking服务
- 求有符号数的原码、反码和补码【C语言】
- 【MySQL】数据库进阶之触发器内容详解
- Greenplum 6.x build_ Environment configuration
- [wechat applet: cache operation]
- 2-3 lookup tree
- Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
- Novice entry SCM must understand those things
- QT charts use (rewrite qchartview to realize some custom functions)
猜你喜欢

MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
![[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology](/img/2a/01db1b84c26502c851786aaca56abe.jpg)
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology

ncs成都新電面試經驗

Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?

Compilation and linking of programs

Data type - floating point (C language)

如何在HarmonyOS应用中集成App Linking服务

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

opencv之图像分割
![[南京大学]-[软件分析]课程学习笔记(一)-introduction](/img/57/bf652b36389d2bf95388d2eb4772a1.png)
[南京大学]-[软件分析]课程学习笔记(一)-introduction
随机推荐
如何在HarmonyOS应用中集成App Linking服务
Required String parameter ‘XXX‘ is not present
Greenplum6.x重新初始化
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
NCS Chengdu Xindian interview experience
Rapid integration of authentication services - harmonyos platform
Qt Charts使用(重写QChartView,实现一些自定义功能)
[kuangbin] topic 15 digit DP
关于基于kangle和EP面板使用CDN
Implementation of navigation bar at the bottom of applet
Mock. JS usage details
SSM integration
【MySQL】数据库进阶之触发器内容详解
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
About using CDN based on Kangle and EP panel
POJ - 3616 Milking Time(DP+LIS)
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
Data type - integer (C language)
ES6_ Arrow function
How to understand distributed architecture and micro service architecture