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 ...
随机推荐
- c# webBrowser清除缓存问题
1.webBrowser的浏览器为ie. 2.通过清除ie缓存即可. 3.代码调用如下: public enum ShowCommands : int { SW_HIDE = , SW_SHOWNOR ...
- RIGHT-BICEP测试第二次程序
根据Right-BICEP单元测试的方法我对我写的第二次程序进行了测试: 测试一:测试能否控制使用乘除 测试二:测试是否能加括号 测试三:是否可以控制题目输出数量 测试四:能否控制输出方式,选择文件输 ...
- U盘安装OSX
1.插入U盘,磁盘工具,格式化U盘为Mac OS X拓展 (日志式): 2.去网站搜索recovery disk assistant,此文件大约1.1M,直接打开使用它制作启动盘,进度条完毕就完成了. ...
- spring框架(3)— spring集合类的注入
1.Car.java package com.eniac.beans; public class Car { private String type; private String factory; ...
- HTML&CSS实体
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 2."结对项目"的心得体会
上个星期,老师给我们布置了个课堂小作业: 某公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道(100以内)四则运算题目给小学生做.二柱立马就想到写一个小程序来做这件事. 这个事情可以用很 ...
- Qt多线程-QThreadPool线程池与QRunnable
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt多线程-QThreadPool线程池与QRunnable 本文地址:https:/ ...
- Sql Server统计报表案例
场景:查询人员指定年月工作量信息 USE [Test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo ...
- APIO/CTSC2017游记
5.10开坑,别问我为啥今天才开始写,前几天玩得太开心了233 5.7 坐火车坐火车,坐地铁坐地铁.其实是第一次坐地铁233.解锁了在地铁上双手玩手机不扶东西站立的姿势? 全程烧流量上QQ,拜大佬约面 ...
- javascript如何封装函数
通常写js组件开发的,都会用到匿名函数的写法去封装一个对象,与外界形成一个闭包的作用域.封装,全天下漫天遍野的封装,JQuery,EXT和Prototype.js封装的是javascript,jQue ...