hdu 4607
来源:互联网 发布:淘宝卖图书好卖吗 编辑:程序博客网 时间:2024/06/06 11:04
#pragma comment(linker, "/STACK:102400000,102400000")#include<iostream>#include<vector>#include<algorithm>#include<cstdio>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<cmath>#include<cassert>#include<cstring>#include<iomanip>#include<ctime>using namespace std;#ifdef _WIN32typedef __int64 i64;#define out64 "%I64d\n"#define in64 "%I64d"#elsetypedef long long i64;#define out64 "%lld\n"#define in64 "%lld"#endif/************ for topcoder by zz1215 *******************/#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)#define FF(i,a) for( int i = 0 ; i < (a) ; i ++)#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)#define S64(a) scanf(in64,&a)#define SS(a) scanf("%d",&a)#define LL(a) ((a)<<1)#define RR(a) (((a)<<1)+1)#define pb push_back#define pf push_front#define X first#define Y second#define CL(Q) while(!Q.empty())Q.pop()#define MM(name,what) memset(name,what,sizeof(name))#define MC(a,b)memcpy(a,b,sizeof(b))#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)<(b)?(a):(b))#define read freopen("in.txt","r",stdin)#define write freopen("out.txt","w",stdout)const int inf = 0x3f3f3f3f;const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;const double oo = 10e9;const double eps = 10e-9;const double pi = acos(-1.0);const int maxn = 101111;int T;int n, m;vector<int>g[maxn];int dp[maxn];bool vis[maxn];int maxlen;int dfs(int now){vis[now] = true;dp[now] = 0;int to,temp;vector<int>v;v.push_back(0);v.push_back(0);for (int i = 0; i < g[now].size(); i++){to = g[now][i];if (!vis[to]){v.push_back(dfs(to) + 1);}}sort(v.begin(), v.end());reverse(v.begin(), v.end());dp[now] = v[0];maxlen = max(maxlen, v[0] + v[1]);return dp[now];}void start(){for (int i = 1; i <= n; i++){vis[i] = false;}maxlen = 0;dfs(1);return;}int main(){cin >> T;while (T--){cin >> n >> m;for (int i = 1; i <= n; i++){g[i].clear();}int now, to;for (int i = 1; i < n; i++){cin >> now >> to;g[now].push_back(to);g[to].push_back(now);}start();int x;for (int i = 1; i <= m; i++){cin >> x;if (x <= maxlen + 1){printf("%d\n", x - 1);}else{printf("%d\n", x * 2 - maxlen - 2);}}}return 0;}
0 0
- HDU 4607
- hdu 4607
- hdu 4607
- hdu 4607 Park Visit
- hdu 4607 Park Visit
- hdu - 4607 - Park Visit
- hdu 4607 Park Visit
- hdu-4607-Park Visit
- HDU 4607 Park Visit
- HDU 4607 Park Visit
- hdu 4607 (树形DP)
- HDU 4607 Park Visit
- hdu 4607 Park Visit
- hdu 4607 Park Visit
- hdu 4607 Park Visit
- HDU - 4607 Park Visit
- HDU 4607 Park Visit
- HDU 4607 Park Visit
- MyEclipse修改自动生成注释模版
- POJ 3134 Power Calculus (IDA*)
- 存:保存结果的内容到一个新【号】里 20140728 ⑧平台控制
- 关于oracle with as用法
- java——控制台输入打印图形
- hdu 4607
- C#:读取数据DataReader
- Linux 知识拾遗 (1) 常用命令
- tar使用记录
- JavaBean(章节摘要)
- 指针编程题
- 浅析背包系统
- C++ primer(第五版) 练习 4.31 个人code 和 疑惑
- 得分突然一天天法国风格让他让他哥哥哥