Prufer Code
1069. Prufer Code
Memory limit: 8 MB
Input
Output
Sample
input | output |
---|---|
2 1 6 2 6 |
1: 4 6 |
Problem Source: Ural State Univerisity Personal Contest Online February'2001 Students Session
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring> using namespace std; const int MAXN = ;
int node[MAXN];
int flag[MAXN]; //数字i在数列中出现了flag[i]次 struct Cmp //自定义运算符
{
bool operator() (const int& x, const int& y)
{
return x > y;
}
}; priority_queue<int, vector<int>, Cmp> son[MAXN]; int main()
{
memset(flag, , sizeof(flag));
int n = ; //n-顶点数
//输入
while(~scanf("%d", &node[n]))
{
flag[node[n++]]++;
}
//处理:算出每一个节点的儿子,存于堆中
for(int i = ; i < n; i++)
{
for(int j = ; j <= n; j++)
{
if(!flag[j])
{
flag[j] = -; //-1表明该节点已经删除
son[node[i]].push(j);
son[j].push(node[i]);
break;
}
}
flag[node[i]]--;
}
//输出结果
for(int i = ; i <= n; i++)
{
printf("%d:", i);
while(!son[i].empty())
{
printf(" %d", son[i].top());
son[i].pop();
}
puts("");
}
return ;
}
Prufer Code的更多相关文章
- ural 1069. Prufer Code
1069. Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without c ...
- URAL 1069 Prufer Code(模拟)
Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...
- URAL 1069 Prufer Code 优先队列
记录每个节点的出度,叶子节点出度为0,每删掉一个叶子,度数-1,如果一个节点的出度变成0,那么它变成新的叶子. 先把所有叶子放到优先队列中. 从左往右遍历给定序列,对于root[i],每次取出叶子中编 ...
- Code the Tree(图论,树)
ZOJ Problem Set - 1097 Code the Tree Time Limit: 2 Seconds Memory Limit: 65536 KB A tree (i.e. ...
- poj 2567 Code the Tree 河南第七届省赛
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2350 Accepted: 906 Desc ...
- Code the Tree
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2292 Accepted: 878 Description A tree ...
- POJ Code the Tree 树的pufer编号
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2259 Accepted: 859 Desc ...
- 第七届河南省赛G.Code the Tree(拓扑排序+模拟)
G.Code the Tree Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 18 [Submit][Status][Web ...
- 【转】ACM 2567 -- 树的Prufer编码
本文介绍北京大学ACM网站2567号题目的解法.介绍部分基本翻译自网站上的题目介绍. 题目介绍: 给定一棵各节点编号为整数1,2,3...n的树(例如,无环连通图),其Prufer编码(Pruf ...
随机推荐
- 判断字符串中是否存在的几种方案:string.indexof、string.contains、list.contains、list.any几种方式效率对比
我们在做项目时,可能会遇到这样的需求,比如判断,1,2,3,33,22,123, 中是否存在,3,. var str=",1,2,3,33,22,123,"; 一般有几种方式: 1 ...
- 2nd scrum站立会议
scrum站立会议 站立会议是让团队成员每日面对面站立互相交流他们所承担任务的进度.它的一个附带好处是让同组成员了解到工作的情况.本质上是为了团队交流,不是会议报告. 站立会议的目的: 1.让整个团队 ...
- (五)Jmeter中的属性和变量
一.Jmeter中的属性: 1.JMeter属性统一定义在jmeter.properties文件中,我们可以在该文件中添加自定义的属性 2.JMeter属性在测试脚本的任何地方都是可见的(全局),通常 ...
- Q3 大型科技公司季报
1. alphabet Alphabet(谷歌母公司)今天发布了截至9月30日的2018财年第三季度财报.报告显示,Alphabet第三季度总营收为337.40亿美元,比上年同期的277.72亿美元增 ...
- PHP上传文件限制的大小
修改PHP上传文件大小限制的方法 1. 一般的文件上传,除非文件很小.就像一个5M的文件,很可能要超过一分钟才能上传完.但在php中,默认的该页最久执行时间为 30 秒.就是说超过30秒,该脚本就停止 ...
- laya3d 文件格式
先认识下laya3d的一些文件 导出文件说明: ls --- 场景文件: Json文件,包含场景中所有节点的数据信息,包含光照贴图信息 ...
- Mybatis 映射关系
相比 Hibernate,Mybatis 的映射关系就显得简单了很多. 未完待续....
- Vue2.0 - 全局操作 Vue.set
引:http://www.cnblogs.com/zccblog/p/7192420.html Vue.set 的作用就是在构造器外部操作构造器内部的数据.属性或者方法.比如在vue构造器内部定义了一 ...
- 点击除指定元素以外的任意地方隐藏js
$(document).click(function () { $(".search_box").hide(); }); $(".resultUl").on(& ...
- 【Asp.Net Core】在Visual Studio 2017中使用Asp.Net Core构建Angular4应用程序
前言 Visual Studio 2017已经发布了很久了.做为集成了Asp.Net Core 1.1的地表最强IDE工具,越来越受.NET系的开发人员追捧. 随着Google Angular4的发布 ...