HDU4707:Pet(DFS)】的更多相关文章

Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in the room but didn’t find the hamster. He tried to use some cheese to trap the hamster. He put the cheese trap in his room and waited for…
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 472 Accepted Submission(s): 229 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in…
http://acm.hdu.edu.cn/showproblem.php?pid=4707 题意:判断距离大于D的点有多少个. 思路: 邻接表建图,dfs每一个点,记录步数. #include <stdio.h> #include <string.h> ; int vis[N],dis[N],head[N],cnt,step; struct node { int u; int v; int next; } edge[N]; void add(int u,int v) { edge…
Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1754    Accepted Submission(s): 847 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searc…
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 535 Accepted Submission(s): 258 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in…
Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1809    Accepted Submission(s): 874 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He sear…
http://acm.hdu.edu.cn/showproblem.php?pid=4707 [题目大意]: Lin Ji 的宠物鼠丢了,在校园里寻找,已知Lin Ji 在0的位置,输入N D,N表示校园中点的个数,D表示宠物鼠不可能在距离D之内,接下来N-1行,输入x,y,表示x与y相邻,(相邻两点之间的距离为1,不相邻为inf),不存在环结构. [题解]: 用邻接表存储树形结构,然后用DFS遍历图 [code]: #include <iostream> #include <stdio…
题意:linji的仓鼠丢了,他要找回仓鼠,他在房间0放了一块奶酪,按照抓鼠手册所说,这块奶酪可以吸引距离它D的仓鼠,但是仓鼠还是没有出现,现在给出一张关系图,表示各个房间的关系,相邻房间距离为1,而且图中没有回路,每个房间都是联通的,求仓鼠可能出现的房间的数量. 很容易的dfs,50000个房间数据量比较大,用数组难以保存,于是用vector储存关系表.遍历过去,遍历过几个房间,那剩下的就是仓鼠可能出现的房间数了. 代码: /* * Author: illuz <iilluzen[at]gmai…
Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in the room but didn’t find the hamster. He tried to use some cheese to trap the hamster. He put the cheese trap in his room and waited for…
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in th…