题目: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 ;
}

最新文章

  1. 解决 git 提交文件提示 Filename too long 问题
  2. C# 线程(六):定时器
  3. how to reset mac root password
  4. Floyd-Warshall算法详解(转)
  5. php yield
  6. JAVAEE学习路线分享
  7. BestCoder Round #32_1001 以及 hdu 5182
  8. [转]Linux 基本操作(RM 删除)
  9. spring生命周期流程图
  10. Go Revel - i18n(国际化)
  11. Bodymovin:Bodymovin和Lottie:把AE动画转换成HTML5/Android/iOS原生动画
  12. PyQt5--QPixmap
  13. MySQL中模拟oracle中的rownum列
  14. TensorFlow相关的一些技巧
  15. python 多线程删除MySQL表
  16. vc 使窗口置顶 在最前面
  17. AIMR 固定收益推荐读物
  18. CLR VIA C# 泛型的协变和逆变
  19. MySQL隐式转换测试
  20. 如何将查询到的数据显示在DataGridView中

热门文章

  1. 【转】 c++拷贝构造函数(深拷贝,浅拷贝)详解
  2. C#实现网络传输数据加密
  3. nodejs npm install全局安装和本地安装的区别
  4. CentOS6.5 MySQL 配置设置总结笔记
  5. HTML中href的链接刷新页面问题
  6. 拓展,Fibonacci螺旋
  7. (转)Qt Model/View 学习笔记 (七)——Delegate类
  8. 使用NPIO操作Excel
  9. iOS 基础 第二天(0805)
  10. Redis之七种武器