题目: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. php环境扩展包so

    http://files.cnblogs.com/files/adtuu/no-debug-non-zts-20121212.zip /Applications/XAMPP/xamppfiles/li ...

  2. wampsever在win10中安装扩展掉坑

    1.必须要退出wampserver 2.php pecl + 3.wampserver 64 3.0.6

  3. 思道OA PK 通达OA 同场竞技 谁与争锋

    技术架构 思道OA 通达OA 开发语言 微软ASP.NET 4.0 PHP开源脚本语言 64位平台 64位 32位 数据库 SQL Server大数据库 MySQL开源数据库 官网下载 下载地址 下载 ...

  4. Kakfa揭秘 Day6 Consumer源码解密

    Kakfa揭秘 Day6 Consumer源码解密 今天主要分析下Consumer是怎么来工作的,今天主要是例子出发,对整个过程进行刨析. 简单例子 Example中Consumer.java是一个简 ...

  5. python安装与环境变量配置

    默认情况下,在windows下安装python之后,系统并不会自动添加相应的环境变量.此时不能在命令行直接使用python命令. 1. 首先需要在系统中注册python环境变量:假设python的安装 ...

  6. Linux vi 中搜索关键字

    当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢? 在vi里可没有菜单-〉查找 不过没关系,可以在命令模式下敲斜杆( / )这时在状态栏(也就是屏幕左下脚)就出现了 “/” 然 ...

  7. 删除_desktop.ini病毒文件

    del h:\_desktop.ini /f/s/q/a/f 强制删除只读文件/s 从当前目录及其所有子目录栓出指定文件.显示正在删除的文件名/q 制定清音状态.不提示确认删除/a 按照属性来删除

  8. 如何将无线路由器作为交换机,将光猫(路由器A)分出来的一条网线接到自家另一台路由器B上,最大化利用网络资源

    从隔壁邻居只接了一条网线过来,由于无线网络的距离有限,不能覆盖到家里任何角落,然而,我又想家里一台台式电脑和无线设备都能够连接wifi进行上网。 摸索了一个上午,知道将家里的无线路由器B当作一个无线A ...

  9. 【BZOJ 2875】 [Noi2012]随机数生成器

    Description  给你6个数,m, a, c, x0, n, g Xn+1 = ( aXn + c ) mod m,求Xn m, a, c, x0, n, g<=10^18 Input ...

  10. 运行windows系统工具命令

    appwiz.cpl 卸载/安装程序  wscui.cpl 操作中心 inetcpl.cpl  查看Internet属性  eventvwr     查看监视消息和疑难解答消息  taskmgr  任 ...