摘要:
题目链接这题Balance Act那题差不多,不过这题的数据量更大,时间有点卡,我的O(N)的算法都跑了1100多MS(时限2S)。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <vector> 4 #define N 50005 5 #define MAX(a,b) ((a)>(b)?(a):(b)) 6 using namespace std; 7 vector<int> dep[N]; 8 int u[2*N],v[2*N],first[N],next[ 阅读全文
posted @ 2012-04-27 20:04
BeatLJ
阅读(219)
评论(0)
推荐(0)
摘要:
题目链接题目大意:给定一棵树,树的每个结点有一个权值,每个结点的权值=去掉该结点后剩余的分支中结点最多的那个分支的结点数。求树中权值最小的结点。这题CE了两次,第一次因为使用了memset没包含头文件,第二次是因为GNU C++没有头文件<memory.h>,使用<string.h>就AC了。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <vector> 4 #define N 20000 5 #define MAX(a,b) ((a)>(b)?( 阅读全文
posted @ 2012-04-27 15:08
BeatLJ
阅读(295)
评论(0)
推荐(0)
摘要:
题目链接这题要用左二子,右兄弟的存储结构来存树(附加一个结点0,将森林连成树),然后就是在二叉树上DP。View Code 1 #include <stdio.h> 2 #include <memory.h> 3 #define MAX(a,b) ((a)>(b)?(a):(b)) 4 #define N 205 5 int son[N],bro[N],w[N],n,m; 6 int c[N][N]; 7 void Insert(int u,int fa,int x) 8 { 9 w[u]=x;10 if(son[fa]==-1) son[fa]=u;11 els 阅读全文
posted @ 2012-04-27 09:50
BeatLJ
阅读(249)
评论(0)
推荐(0)

浙公网安备 33010602011771号