Pet

点击打开链接

bfs,需要自己构图

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>

using namespace std;

const int maxn = 100005;
int dep[ maxn ];
int vis[ maxn ];
int pre[ maxn ];
vector< int >mapp[ maxn ];

void Bfs( int s ){
	memset( dep, -1, sizeof( dep ) );
	dep[ 0 ] = 0;
	queue< int > q;
	q.push( s );
	while( !q.empty() ){
		int u = q.front();
		q.pop();
		int sz = mapp[ u ].size();
		for( int i = 0; i < sz; ++i ){
			int v = mapp[ u ][ i ];
			if( dep[ v ] != -1 )
				continue;

			dep[ v ] = dep[ u ] + 1
			q.push( v );
		}
	}
}

int main(){
	int Case, n, d, u, v;
	scanf( "%d", &Case );
	while( Case-- ){
		scanf( "%d%d", &n, &d );
		for( int i = 0; i < n; ++i )
			mapp[ i ].clear();
		for( int i = 1; i < n; ++i ){
			scanf( "%d%d", &u, &v );
			mapp[ u ].push_back( v );
			mapp[ v ].push_back( u );
		}
		Bfs( 0 );
		int ans = 0;
		for( int i = 0; i < n; ++i ){
			if( dep[ i ] > d ){
				ans++;
			}
		}
		printf( "%d\n", ans );
	}
	return 0;
}

Pet

时间: 2024-07-30 04:25:22

Pet的相关文章

HDU 4707 Pet

Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1909    Accepted Submission(s): 924 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searc

Pet(dfs+vector)

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

get a new level 25 battle pet in about an hour

If you have 2 level 25 pets and any level 1 pet, obviously start with him in your lineup. Defeat all eastern kingdoms pet trainers in order of level (don't know exact order, but just do this). This should get you to around 15-17. Go to dragonblight a

hdu 4707 Pet(dfs,bfs)

Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1548    Accepted Submission(s): 733 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He sear

杭电 4707 pet(并查集求元素大于k的集合)

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 three da

Pet(hdu 4707 BFS)

Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2052    Accepted Submission(s): 1007 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He sear

【ThinkingInJava】31、对pet进行计数(3)

我们不在使用前面那种笨拙的方式,n个instanceof来判断了 /** * 书本:<Thinking In Java> * 功能:为了对pet进行计数,我们做一个能跟踪各种不同类型的Pet的数量的工具,用map.这里使用动态instanceof() * 文件:PetCount3.java * 时间:2015年4月14日09:25:29 * 作者:cutter_point */ package Lesson14TypeInformation; import java.util.LinkedHa

hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

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

Microsoft .NET Pet Shop 4: Migrating an ASP.NET 1.1 Application to 2.0

249 out of 297 rated this helpful - Rate this topic Gregory LeakeMicrosoft Corporation Alan Le, Alex Arkhipov, Mike Hanley, and Steve NyholmVertigo Software, Inc. February 2006 Applies to:    Microsoft .NET Framework 2.0     Microsoft Visual Studio 2

Tips for Making Your Pet Dog Wear Collar

Dogs may refuse to wear dog collars at the very beginning, and many dog keepers feel confused and helpless. Collars can help pet keepers to manage their pets better and control their behaviors, but what is your dog is just unwilling to do that? Here