码迷,mamicode.com
首页 > 其他好文 > 详细

ranse

时间:2017-06-05 23:42:19      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:i++   algorithm   getch   tree   int   getchar   stat   color   algo   

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100000000
int son[maxn],hson[maxn],top[maxn],deep[maxn],id[maxn],tree[maxn];
int to[maxn],next[maxn],pre[maxn];
int color[maxn],soncolor[maxn];
int n,m,M;
inline int RD()
{
char ch;
int res=0;
ch=getchar();
while(ch<‘0‘||ch>‘9‘)ch=getchar();
res=ch-‘0‘;
while((ch=getchar())>=‘0‘&&ch<=‘9‘)res=res*10+ch-‘0‘;
return res;
}
void addedge(int a,int b)
{
static int tip=0;
next[++tip]=pre[a],pre[a]=tip,to[tip]=b;
next[++tip]=pre[b],pre[b]=tip,to[tip]=a;
}
void dfs1(int father,int now)
{
deep[now]=deep[father]+1;
for(int i=pre[now];i;i=next[now])
{
if(to[i]!=father)
{
dfs1(now,to[i]);
son[now]+=son[to[i]];
if(son[to[i]]>son[hson[now]])hson[now]=to[i];
}
}
if(!son[now])son[now]=1;
}
void dfs2(int father,int now)
{
static int ID=0;
id[now]=++ID;
if(hson[now])dfs2(now,hson[now])
}
int main()
{
n=RD(),m=RD();
for(int i=1;i<=n;i++)color[i];
for(int i=1;i<n;i++)addedge(RD(),RD());
for(M=1;M<n;M>>1);
dfs1(1,1);dfs2(1,1);
}

ranse

标签:i++   algorithm   getch   tree   int   getchar   stat   color   algo   

原文地址:http://www.cnblogs.com/OcahIBye/p/6947330.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!