POJ 2513 Colored Sticks
Time Limit: 5000MS | Memory Limit: 128000K | |
Total Submissions: 28036 | Accepted: 7428 |
Description
Input
Output
Sample Input
blue red
red violet
cyan blue
blue magenta
magenta cyan
Sample Output
Possible
Hint
Source
无向图欧拉通路:连通图+两个点的度数是奇数。。。。。
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxnode=;
int worldnum=,Father[],USize[],degree[]; struct Trie
{
int tot,root,child[maxnode][];
int flag[maxnode];
Trie()
{
memset(child[],,sizeof(child[]));
memset(flag,-,sizeof(flag));
root=tot=;
}
void Insert(const char* str)
{
int *cur=&root;
for(const char* p=str;*p;*p++)
{
cur=&child[*cur][*p-'a'];
if(*cur==)
{
*cur=tot++;
memset(child[tot],,sizeof(child[tot]));
flag[tot]=-;
}
}
flag[*cur]=worldnum++;
} int Query(const char*str)
{
int* cur=&root;
for(const char* p=str;*p&&*cur;p++)
{
cur=&child[*cur][*p-'a'];
}
if(*cur&&~flag[*cur])
{
return flag[*cur];
}
else
{
Insert(str);
return worldnum-;
}
}
}T; int Findfather(int x)
{
if(Father[x]==x)
{
return x;
}
else
{
Father[x]=Father[Father[x]];
return Findfather(Father[x]);
}
} void Disjoin()
{
for(int i=;i<;i++)
{
Father[i]=i; USize[i]=;
}
} void Unionset(int a,int b)
{
int Fa=Findfather(a);
int Fb=Findfather(b);
if(Fa==Fb) return ;
if(USize[Fa]>=USize[Fb])
{
Father[Fa]=Fb;
USize[Fb]+=USize[Fa];
}
else
{
Father[Fb]=Fa;
USize[Fa]+=USize[Fb];
}
} int main()
{
char str1[],str2[];
Disjoin();
while(scanf("%s %s",str1,str2)!=EOF)
{
int a=T.Query(str1);
int b=T.Query(str2);
degree[a]++; degree[b]++;
Unionset(a,b);
}
int sum=;
for(int i=;i<worldnum;i++)
{
if(degree[i]%==) sum++;
}
if(sum>) { puts("Impossible"); return ;}
for(int i=;i<worldnum;i++)
{
if(Findfather()!=Findfather(i))
{ puts("Impossible"); return ;}
}
puts("Possible");
return ;
}
POJ 2513 Colored Sticks的更多相关文章
- poj 2513 Colored Sticks(欧拉路径+并检查集合+特里)
题目链接:poj 2513 Colored Sticks 题目大意:有N个木棍,每根木棍两端被涂上颜色.如今给定每一个木棍两端的颜色.不同木棍之间拼接须要颜色同样的 端才干够.问最后是否能将N个木棍拼 ...
- [欧拉] poj 2513 Colored Sticks
主题链接: http://poj.org/problem? id=2513 Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Tota ...
- poj 2513 Colored Sticks trie树+欧拉图+并查集
点击打开链接 Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27955 Accepted ...
- poj 2513 Colored Sticks (trie 树)
链接:poj 2513 题意:给定一些木棒.木棒两端都涂上颜色,不同木棒相接的一边必须是 同样的颜色.求能否将木棒首尾相接.连成一条直线. 分析:能够用欧拉路的思想来解,将木棒的每一端都看成一个结点 ...
- POJ 2513 Colored Sticks (欧拉回路 + 字典树 +并查集)
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27097 Accepted: 7175 ...
- poj 2513 Colored Sticks (trie树+并查集+欧拉路)
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 40043 Accepted: 10406 ...
- POJ 2513 - Colored Sticks - [欧拉路][图的连通性][字典树]
题目链接: http://poj.org/problem?id=2513 http://bailian.openjudge.cn/practice/2513?lang=en_US Time Limit ...
- poj 2513 Colored Sticks( 字典树哈希+ 欧拉回路 + 并查集)
题目:http://poj.org/problem?id=2513 参考博客:http://blog.csdn.net/lyy289065406/article/details/6647445 htt ...
- POJ 2513 Colored Sticks 字典树、并查集、欧拉通路
Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some ...
随机推荐
- 记录毕业论文 LanguageTool 二次开发时用到的网站
LanguageTool Development LanguageTool Supported Languages Share your knowledge about LT - LanguageTo ...
- storm如何保证at least once语义?
背景 前期收到的问题: 1.在Topology中我们可以指定spout.bolt的并行度,在提交Topology时Storm如何将spout.bolt自动发布到每个服务器并且控制服务的CPU.磁盘等资 ...
- 云计算之路-阿里云上:2014年6月12日14:40出现CPU 100%
这是今天遇到的第2次故障,主站1台云服务器在14:40:33-14:41:09期间出现CPU突然跑满的状况,而CPU跑满之前,请求量并没有明显增长. 向阿里云提交之后,说晚上会对这台云服务器的虚拟机进 ...
- VC6.0中MFC界面换肤简例
利用VC中的MFC进行界面设计时,发现界面上的各控件无法简易地进行调整,比如字体大小.颜色.格式等. 为了改变外观,小小地美化一下,今天决定动手一试. 网上提供的库和方法不计其数,我选择了SkinMa ...
- 字符串string类型转换成DateTime或DateTime?类型
常用的Convert.ToDateTime方法 //将含有正确日期格式的string类型转换成DateTime类型 string strDate = "2014-08-01"; D ...
- [BZOJ2753][SCOI2012]滑雪与时间胶囊(特殊的有向树形图)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2753 分析: 第一问:直接BFS扩展知道无法扩展 第二问: 看似就是最小树形图啊= = ...
- Linq表达式开窍
static IQueryable<T> GetPageList<T,TKey>(Expression<Func<T,bool>> whereLambd ...
- nginx 日志怎么实现显示真实客户端IP
这篇文章页不错: http://www.tuicool.com/articles/E32mYf 假如说我们现在的架构是,nginx做反向代理,apache做web服务器.那么我们怎么让我的web服务器 ...
- 【POJ 1273】Drainage Ditches(网络流)
一直不明白为什么我的耗时几百毫秒,明明差不多的程序啊,我改来改去还是几百毫秒....一个小时后:明白了,原来把最大值0x3f(77)取0x3f3f3f3f就把时间缩短为16ms了.可是为什么原来那样没 ...
- 【CodeForces 621A】Wet Shark and Odd and Even
题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...