You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

///*
// * map03.cpp
// *
// * Created on: May 10, 2024
// * Author: 28032
// */
////1.采用数组将每个结点的猫数储存
////2.用set储存树
////3.采用DFS当进入一个结点时检查该节点的猫数
////如果为0将累计的猫数归零如果不为零累计的猫数加上该节点
////然后判断猫数是否大于m如果大于直接return
////之后依次对该节点的邻接点进行DFS
//
//#include <iostream>
//#include <set>
//
//using namespace std;
//
//int n,m,cnt = 0;
//int * cat;
//set<int>* G;
//set<int> visited;
//
//void DFS(int curr,int Cat)
//{
// if(visited.find(curr) != visited.end())
// return ;
//
// visited.insert(curr);
//
// if(cat[curr])
// Cat += cat[curr];
// else
// Cat = 0;
//
// if(Cat > m)
// return ;
//
// for(int chil : G[curr])
// {
// DFS(chil,Cat);
// }
//
// if(G[curr].size() == 1 && curr != 1)
// cnt++;
//}
//
//int main()
//{
// cin>>n>>m;
//
// cat = new int[n+1];
// G = new set<int>[n+1];
//
// for(int i = 1;i <= n;i++)
// {
// int a;
// cin>>a;
// cat[i] = a;
// }
//
// for(int i = 1;i < n;i++)
// {
// int a,b;
// cin>>a>>b;
// G[a].insert(b);
// G[b].insert(a);
// }
//
// DFS(1,0);
//
// cout<<cnt<<endl;
//
// delete[] cat;
// delete[] G;
//
//
// return 0;
//}
//
//