题意:删除一棵树上的叶子 每删除一片叶子就写下连着该片叶子的节点  让你还原一棵树

记录每个节点连着的叶子数 0表示此时这个节点就是叶子  -1表示这个节点已经删除 删除的只能是0  就是说是叶子 暴力一下就好了

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> g[7550];
int a[7550];
int b[7550];
int main()
{
int n = 0;
memset(b , 0, sizeof(b));
while(scanf("%d",&a[n]) == 1)
{
b[a[n]]++;
n++;
}
for(int i = 1; i <= n+1; i++)
g[i].clear();
for(int i = 0; i < n; i++)
{
if(b[a[i]] > 0)
{
for(int j = 1; j <= n+1; j++)
if(b[j] == 0)
{
g[a[i]].push_back(j);
g[j].push_back(a[i]);
b[j]--;
b[a[i]]--;
break;
}
}
}
for(int i = 1; i <= n+1; i++)
{
sort(g[i].begin(), g[i].end());
printf("%d:",i);
int len = (int)g[i].size();
for(int j = 0; j < len; j++)
printf(" %d",g[i][j]);
puts("");
}
return 0;
}

ural 1069的更多相关文章

  1. ural 1069. Prufer Code

    1069. Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without c ...

  2. URAL 1069 Prufer Code(模拟)

    Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...

  3. URAL 1069 Prufer Code 优先队列

    记录每个节点的出度,叶子节点出度为0,每删掉一个叶子,度数-1,如果一个节点的出度变成0,那么它变成新的叶子. 先把所有叶子放到优先队列中. 从左往右遍历给定序列,对于root[i],每次取出叶子中编 ...

  4. 并查集补集作法 codevs 1069 关押罪犯

    1069 关押罪犯 2010年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description ...

  5. HDU 1069 dp最长递增子序列

    B - Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  6. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  7. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  8. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  9. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

随机推荐

  1. Swift构造器(Initializer)与析构器(Deinitializer)

    为了初始化结构体和类等类型的实例属性. 默认构造器 struct Fahrenheit { var temperature: Doubleinit(){ temperature = 32.0 } } ...

  2. 跨域访问JSONP CORS

    一.JSONP 常用的Jquery框架支持jsonp方式请求,该方式只支持GET方法,传参大小有限,而且需要后台根据jsonp的请求方式进行封装结果返回. 其中参数jsonp默认为callback,j ...

  3. StringBuilder和StringBuffer

    StringBuilder java.lang 类 StringBuilder java.lang.Object java.lang.StringBuilder 所有已实现的接口: Serializa ...

  4. spring aop配置及用例说明(4)

    欢迎交流转载:http://www.cnblogs.com/shizhongtao/p/3476161.html 这里简单对xml的配置方式做一下描述.代码还是上一篇(http://www.cnblo ...

  5. ArcSDE for oracle10g安装后post的时候出现错误

    The Post Installation Setup can not locate required Oracle files in your path.Check your Oracle inst ...

  6. 119. Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  7. CVTE面试总结

    刚面完了CVTE的一面,感觉完败,现总结. 一:准备不充分 这个跟时间仓促也有关系.昨天下午收到通知,晚上九点多回来填写给定格式的简历,题目也比较多.由于时间较仓促,那些问题的答案没有过多斟酌.但糟糕 ...

  8. how to Enable Client Integration

    i got a problem,the problem is list cant use export to excel button in sharepoint 2010. I found my a ...

  9. php程序备份还原mysql数据库

    <?php $link = mysql_connect("localhost", "root",""); mysql_query(&q ...

  10. SQL正常工作日上班安排

    alter proc [work] as declare @i int begin id into #restdate from dt_work where work_date in (select ...