POJ Code the Tree 树的pufer编号
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2259 | Accepted: 859 |
Description
Your task is, given a tree, to compute its Prufer code. The tree is
denoted by a word of the language specified by the following grammar:
T ::= "(" N S ")"
S ::= " " T S
| empty
N ::= number
That is, trees have parentheses around them, and a number denoting
the identifier of the root vertex, followed by arbitrarily many (maybe
none) subtrees separated by a single space character. As an example,
take a look at the tree in the figure below which is denoted in the
first line of the sample input. To generate further sample input, you
may use your solution to Problem 2568.
Note that, according to the definition given above, the root of a
tree may be a leaf as well. It is only for the ease of denotation that
we designate some vertex to be the root. Usually, what we are dealing
here with is called an "unrooted tree".
Input
input contains several test cases. Each test case specifies a tree as
described above on one line of the input file. Input is terminated by
EOF. You may assume that 1<=n<=50.
Output
each test case generate a single line containing the Prufer code of the
specified tree. Separate numbers by a single space. Do not print any
spaces at the end of the line.
Sample Input
(2 (6 (7)) (3) (5 (1) (4)) (8))
(1 (2 (3)))
(6 (1 (4)) (2 (3) (5)))
Sample Output
5 2 5 2 6 2 8
2 3
2 1 6 2 6
Source
POJ Code the Tree 树的pufer编号的更多相关文章
- POJ 3321 Apple Tree(树状数组)
Apple Tree Time Limit: 2000MS Memory Lim ...
- POJ 3321 Apple Tree (树状数组+dfs序)
题目链接:http://poj.org/problem?id=3321 给你n个点,n-1条边,1为根节点.给你m条操作,C操作是将x点变反(1变0,0变1),Q操作是询问x节点以及它子树的值之和.初 ...
- 【POJ 1741】 Tree (树的点分治)
Tree Description Give a tree with n vertices,each edge has a length(positive integer less than 100 ...
- POJ 3321 Apple Tree 树状数组+DFS
题意:一棵苹果树有n个结点,编号从1到n,根结点永远是1.该树有n-1条树枝,每条树枝连接两个结点.已知苹果只会结在树的结点处,而且每个结点最多只能结1个苹果.初始时每个结点处都有1个苹果.树的主人接 ...
- POJ 2486 Apple Tree [树状DP]
题目:一棵树,每个结点上都有一些苹果,且相邻两个结点间的距离为1.一个人从根节点(编号为1)开始走,一共可以走k步,问最多可以吃多少苹果. 思路:这里给出数组的定义: dp[0][x][j] 为从结点 ...
- POJ 2486 Apple Tree ( 树型DP )
#include <iostream> #include <cstring> #include <deque> using namespace std; #defi ...
- POJ 3321 Apple Tree 树状数组 第一题
第一次做树状数组,这个东西还是蛮神奇的,通过一个简单的C数组就可以表示出整个序列的值,并且可以用logN的复杂度进行改值与求和. 这道题目我根本不知道怎么和树状数组扯上的关系,刚开始我想直接按图来遍历 ...
- POJ 3321 Apple Tree 【树状数组+建树】
题目链接:http://poj.org/problem?id=3321 Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- Code the Tree(图论,树)
ZOJ Problem Set - 1097 Code the Tree Time Limit: 2 Seconds Memory Limit: 65536 KB A tree (i.e. ...
随机推荐
- mybatis15 mapper方式 代码
UserMapper.java package cn.itcast.mybatis.mapper; import java.util.List; import cn.itcast.mybatis.po ...
- 模板类之间的友元关系实现Blob和BlobPtr
16.12编写你自己版本的Blob和BlobPtr模板,包含书中未定义的多个const成员. Blob.h(注意,成员函数的声明和定义要放在一个头文件中) /*记住,模板的头文件中通常既包括声明也包括 ...
- C# DataTable怎么合计字段
DataTable dt = new DataTable(); var age=dt.Compute("avg(age)",""); var height =d ...
- XPath操作XML文档
NET框架下的Sytem.Xml.XPath命名空间提供了一系列的类,允许应用XPath数据模式查询和展示XML文档数据. 3.1XPath介绍 主要的目的是在xml1.0和1.1文档节点树种定位节点 ...
- 自己写的demo---声明异常同时处理异常,或者继续抛出异常
package exception; public class exception { public static void main(String args[]) { /*** * 不能对类型 ex ...
- jquery ajax获取和解析数据
最近项目中用到了ajax技术,之前虽然写过一点点,但是没有系统的总结过.趁着刚刚用过,手热就记录一下,方便以后查阅. $.ajax中的参数 $.ajax的函数格式: $.ajax({ type: 'P ...
- javascript类继承系列二(原型链)
原型链是采用最主要的继承方式,原理:每一个类(构造器,js中的function)都有一个原型属性(prototype)指向一个原型对象,原型对象有一个构造器(constructor),它又指回到fun ...
- Ubuntu下Hadoop快速安装手册
http://www.linuxidc.com/Linux/2012-02/53106.htm 一.环境 Ubuntu 10.10+jdk1.6 二.下载&安装程序 1.1 Apache Ha ...
- oracle 权限管理
系统权限 系统权限需要授予者有进行系统级活动的能力,如连接数据库,更改用户会话.建立表或建立用户等等.你可以在数据字典视图SYSTEM_PRIVILEGE_MAP上获得完整的系统权限.对象权限和系统权 ...
- web开发基础(同步更新中)
1/Get与Post的区别 GET是我们都熟悉的.它用于请求网页文本.当你在浏览器输入harvard.edu,它会直接访问Harvard的web服务器,去GET /. 第二个最有名的是POST,它经常 ...