当前位置:网站首页>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;
}
边栏推荐
- opencv 将16位图像数据转为8位、8转16
- Input of mathematical formula of obsidan
- [step on the pit] Nacos registration has been connected to localhost:8848, no available server
- Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
- Shell script for changing the current folder and the file date under the folder
- Greenplum6.x搭建_环境配置
- Three usage scenarios of annotation @configurationproperties
- NCS Chengdu Xindian interview experience
- idea里使用module项目的一个bug
- Go语言中,函数是一种类型
猜你喜欢
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"
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
leetcode134. gas station
关于基于kangle和EP面板使用CDN
Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
Download and install orcale database11.2.0.4
About using CDN based on Kangle and EP panel
let const
联想混合云Lenovo xCloud:4大产品线+IT服务门户
随机推荐
uniapp 微信小程序监测网络
Greenplum 6.x build_ install
Greenplum6.x搭建_安装
Thirteen forms of lambda in kotlin
Laravel8 uses passport login and JWT (generate token)
Gson转换实体类为json时报declares multiple JSON fields named
Gson converts the entity class to JSON times declare multiple JSON fields named
Implementation of navigation bar at the bottom of applet
PLSQL的安装和配置
[南京大学]-[软件分析]课程学习笔记(一)-introduction
Data analysis methodology and previous experience summary 2 [notes dry goods]
如何在图片的目标中添加目标的mask
[machine learning] watermelon book data set_ data sharing
POJ - 3616 Milking Time(DP+LIS)
National SMS center number inquiry
Greenplum 6.x common statements
[Yugong series] February 2022 U3D full stack class 005 unity engine view
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
NCS Chengdu Xindian interview experience
Why choose cloud native database