记录编号 43887 评测结果 AAAAAAAA
题目名称 [石门中学 2009]切割树 最终得分 100
用户昵称 GravatarTruth.Cirno 是否通过 通过
代码语言 C++ 运行时间 0.014 s
提交时间 2012-10-15 07:11:57 内存使用 3.41 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int ava=0,ptop[10010],wayto[20010],waynext[20010],v[10010],f[10010];
  6.  
  7. int maxint(int a,int b)
  8. {
  9. if (a>b)
  10. return(a);
  11. return(b);
  12. }
  13.  
  14. void getin(int from,int to)
  15. {
  16. if (ptop[from]==0)
  17. {
  18. ava++;
  19. ptop[from]=ava;
  20. wayto[ava]=to;
  21. }
  22. else
  23. {
  24. int poi;
  25. poi=ptop[from];
  26. while (waynext[poi])
  27. poi=waynext[poi];
  28. ava++;
  29. waynext[poi]=ava;
  30. wayto[ava]=to;
  31. }
  32. }
  33.  
  34. void fillit(int pos,int last)
  35. {
  36. int poi;
  37. poi=ptop[pos];
  38. while (poi)
  39. {
  40. if (wayto[poi]!=last)
  41. {
  42. fillit(wayto[poi],pos);
  43. v[pos]+=v[wayto[poi]]+1;
  44. f[pos]=maxint(f[pos],v[wayto[poi]]+1);
  45. }
  46. poi=waynext[poi];
  47. }
  48. }
  49.  
  50. int main(void)
  51. {
  52. freopen("treecut.in","r",stdin);
  53. freopen("treecut.out","w",stdout);
  54. int i,n,a,b;
  55. bool flag=false;
  56. cin>>n;
  57. for (i=1;i<n;i++)
  58. {
  59. cin>>a>>b;
  60. getin(a,b);
  61. getin(b,a);
  62. }
  63. fillit(1,0);
  64. for (i=1;i<=n;i++)
  65. {
  66. if (f[i]*2<=n&&(n-v[i]-1)*2<=n)
  67. {
  68. cout<<i<<' ';
  69. flag=true;
  70. }
  71. }
  72. if (!flag)
  73. cout<<"NONE\n";
  74. else
  75. cout<<endl;
  76. return(0);
  77. }