ural 1069. 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
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n, arr[N];
int cnt[N];
priority_queue<int> que;
vector<int> ans[N]; inline void Input()
{
int x;
while(cin >> x)
{
arr[n++] = x;
cnt[x]++;
}
n++;
} inline void Solve()
{
for(int i = ; i < n; i++)
if(!cnt[i + ]) que.push(-(i + ));
for(int step = ; step <= n - ; step++)
{
int x = -que.top(), now = arr[step - ];
que.pop();
if(!(--cnt[now])) que.push(-now);
ans[now].pub(x);
ans[x].pub(now);
} for(int i = ; i <= n; i++)
{
printf("%d:", i);
sort(ans[i].begin(), ans[i].end());
int length = sz(ans[i]);
for(int j = ; j < length; j++)
printf(" %d", ans[i][j]);
printf("\n");
}
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
ural 1069. Prufer Code的更多相关文章
- 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],每次取出叶子中编 ...
- Prufer Code
1069. Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without c ...
- URAL 1792. Hamming Code (枚举)
1792. Hamming Code Time limit: 1.0 second Memory limit: 64 MB Let us consider four disks intersectin ...
- Ural 1780 Gray Code 乱搞暴力
原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1780 1780. Gray Code Time limit: 0.5 secondMem ...
- ural 1069
题意:删除一棵树上的叶子 每删除一片叶子就写下连着该片叶子的节点 让你还原一棵树 记录每个节点连着的叶子数 0表示此时这个节点就是叶子 -1表示这个节点已经删除 删除的只能是0 就是说是叶子 暴 ...
- 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 ...
随机推荐
- iOS 访问粘贴板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = self.label.text;
- Orleans是什么 (一)
官网:http://dotnet.github.io/orleans/ 文档:http://dotnet.github.io/orleans/What's-new-in-Orleans 源码:http ...
- Mac OS
defaults write com.apple.finder AppleShowAllFiles -bool true 此命令显示隐藏文件defaults write com.apple.finde ...
- Vs注释,vsXML,VSXML注释
标签名称 说明 语法 参数 <summary> <summary> 标记应当用于描述类型或类型成员.使用<remarks> 添加针对某个类型说明的补充信息. < ...
- 【PHP XML与dtd概述【完整版】】
一.XML文件简介 关于XML的大多数人都知道一些,HTML->xhtml->xml,这个顺序本来应当是HTML发展的顺序. XML可以当做配置文件使用,还可以充当小型的数据库. vers ...
- Code Review for SSIS package
以下是我对SSIS包进行code review的一些建议,如果有其他更好的方案欢迎拍砖. A. 查看是否使用了最优的解决方案 1. 最优的结构视图 2. 解决方案,包,任务,组建,参数的命名使用了易读 ...
- 攻城狮在路上(叁)Linux(十三)--- 文件与目录的管理
一.查看文件与目录: 1.命令格式:ls [-aAdfFhilnrRSt] 目录名称; 2.参数说明: -a:显示所有的文件,包括隐藏文件(隐藏文件一般以.开头). -d:仅列出目录本身. -l:列出 ...
- php开发(CI框架使用)
年前接了一个外包项目,要求使用PHP,琢磨来琢磨去,感叹道PHP框架实在是太多了!去知乎搜索一轮,最后决定使用CI, 相关议论如下:https://www.zhihu.com/question/216 ...
- hdu 4069 福州赛区网络赛I DLC ***
再遇到一个DLC就刷个专题 #include <stdio.h> #include <string.h> #include <iostream> #include ...
- mysql的启动
1.直接用mysqld手工启动 [root@ora11g bin]# ./mysqld --defaults-file=../my.cnf :: [ERROR] Fatal error: Please ...