首页 > 代码库 > [2017.4.8]备忘 造树

[2017.4.8]备忘 造树

造树一定不能忘记啦!!!

技术分享
1 for (RG int i=2;i<=n;++i) fa[i]=rand()%(i-1)+1
2 for (RG int i=1;i<=n;++i) y[i]=i;
3 for (RG int i=1;i<=n;++i) swap(y[i],y[rand()n+1]);
4 for (RG int i=1;i<=n;++i) printf("%d %d\n",y[i],y[fa[i]]);
View Code

 

[2017.4.8]备忘 造树