题目:http://poj.org/problem?id=2513

参考博客:http://blog.csdn.net/lyy289065406/article/details/6647445

http://www.cnblogs.com/LK1994/p/3263462.html

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
#define N 500010
using namespace std; int degree[N],bin[N],id = ; struct tree
{
int flag,id;
struct tree* next[];
}*root;
struct tree* creat()
{
struct tree *p=(struct tree*)malloc(sizeof(struct tree));
p->flag =;
for(int i = ; i < ; i++)
p->next[i] = NULL;
return p;
} int find(int x)
{
if(bin[x] != x)
bin[x] = find(bin[x]);
return bin[x];
} int hash(char s[])
{
struct tree *p = root;
for(int i = ; s[i]; i++)
{
if(p->next[s[i]-'a'] == NULL)
p->next[s[i]-'a'] = creat();
p = p->next[s[i]-'a'];
}
if(p->flag != )
{
p->flag = ;
p->id = id++;
}
return p->id;
} int check()
{
int sum = ;
int x = find();
for(int i = ; i < id; i++)
if(find(i) != x)
return ;
for(int i = ; i < id; i++)
{
if(degree[i]%)
sum++;
}
if(sum == || sum == )
return ;
return ;
} int main()
{
int u,v,x,y;
char s1[],s2[];
memset(degree,,sizeof(degree));
for(int i=; i<=; i++)
bin[i]=i;
root=creat();
while(scanf("%s %s",s1,s2)!=EOF)
{
u =hash(s1); v =hash(s2);
degree[u]++; degree[v]++;
x=find(u);
y=find(v);
if(x!=y)
bin[x]=y;
}
if(check()) printf("Possible\n");
else printf("Impossible\n");
return ;
}

poj 2513 Colored Sticks( 字典树哈希+ 欧拉回路 + 并查集)的更多相关文章

  1. POJ 2513 Colored Sticks 字典树、并查集、欧拉通路

    Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some ...

  2. Colored Sticks (字典树哈希+并查集+欧拉路)

    Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27704   Accepted: 7336 Description You ...

  3. poj 2513 Colored Sticks (trie树+并查集+欧拉路)

    Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 40043   Accepted: 10406 ...

  4. poj 2513 Colored Sticks trie树+欧拉图+并查集

    点击打开链接 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27955   Accepted ...

  5. poj 2513 Colored Sticks (trie 树)

    链接:poj 2513 题意:给定一些木棒.木棒两端都涂上颜色,不同木棒相接的一边必须是 同样的颜色.求能否将木棒首尾相接.连成一条直线. 分析:能够用欧拉路的思想来解,将木棒的每一端都看成一个结点 ...

  6. poj 2513 Colored Sticks(欧拉路径+并检查集合+特里)

    题目链接:poj 2513 Colored Sticks 题目大意:有N个木棍,每根木棍两端被涂上颜色.如今给定每一个木棍两端的颜色.不同木棍之间拼接须要颜色同样的 端才干够.问最后是否能将N个木棍拼 ...

  7. [欧拉] poj 2513 Colored Sticks

    主题链接: http://poj.org/problem? id=2513 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Tota ...

  8. POJ 2513 - Colored Sticks - [欧拉路][图的连通性][字典树]

    题目链接: http://poj.org/problem?id=2513 http://bailian.openjudge.cn/practice/2513?lang=en_US Time Limit ...

  9. POJ 2513 Colored Sticks (欧拉回路+并查集+字典树)

    题目链接 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with ...

随机推荐

  1. PhantomJS实现最简单的模拟登录方案

    以前写爬虫,遇到需要登录的页面,一般都是通过chrome的检查元素,查看登录需要的参数和加密方法,如果网站的加密非常复杂,例如登录qq的,就会很蛋疼 在后面,有了Pyv8,就可以把加密的js文件扔给它 ...

  2. WPF学习笔记4——Layout之2

    下面简单介绍常见的面板. 一.Grid 1.Grid关于调整行列距离有三种方法:绝对大小,自动大小,比例大小.如下: <ColumnDefinition Width="100" ...

  3. Perl内置变量速查表

    [ 文件句柄 ] $| 如果非零, 则在对当前选定的文件执行写或打印操作后强制清除缓冲区 $% 当前选中文件句柄的当前页码 $= 当前选中文件句柄的当前页面长度 $- 当前选中文件句柄的页面剩余长度 ...

  4. 使用泛型 类型“System.Collections.Generic.IEnumerator<T>”需要 1 个类型参数

    解决办法:添加 using System.Collections:命名空间

  5. 第一章 基本的SQL语句 (SQL基础)

    1. 查询数据库系统时间,常以服务器默认的格式进行显示(根据数据库的字符集而定): 注意:dual 为数据库中的虚表,隶属于管理员 sys 用户,但所有的用户都可以访问:无实际意义,仅充当select ...

  6. dnf的动画脚本研究

    . 1.0x00    : 帧数           int16 2.0x02    : 总为1(?) int16 3.0x04  : 资源文件名长度 int32 4.长度+1 :   0,1(未知用 ...

  7. IE9下Coolite.Ext出现createContextualFragment错误

    解决Ext在IE9上报错“createContextualFragment”,只需要在使用Coolite.Ext页面加入如下代码即可: if ((typeof Range !== "unde ...

  8. CROSS APPLY和 OUTER APPLY 区别

    转 http://www.cnblogs.com/end/archive/2011/02/17/1957011.html FROM employees AS e       join employee ...

  9. 1196: [HNOI2006]公路修建问题 - BZOJ

    Description OI island是一个非常漂亮的岛屿,自开发以来,到这儿来旅游的人很多.然而,由于该岛屿刚刚开发不久,所以那里的交通情况还是很糟糕.所以,OIER Association组织 ...

  10. SAX EntityResolver 的作用

    1.1 何为 EntityResolver : 官方解释: 如果SAX应用程序叙事实现自定义处理外部实体,则必须实现此接口, 并使用setEntityResolver方法向SAX 驱动器注册一个实例. ...