POJ 2513 Colored Sticks <trie+并查集+欧拉路径>
来源:互联网 发布:网络拓扑生成器 编辑:程序博客网 时间:2024/06/06 03:14
题目:传送门。
分析:我好懒,直接分享一篇题解吧,传送门。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>using namespace std;const int MAXN=25e4+5;class trieTree{public:int id;trieTree *next[27];trieTree(){id=-1;memset(next,0,sizeof next);}};trieTree root;int degree[MAXN*2];int ancestor[MAXN*2];int color;int getID(char *str){trieTree *t=&root;for(int i=0;str[i]!='\0';++i){int index=str[i]-'a';if(!t->next[index]){trieTree *tt=new trieTree;t->next[index]=tt;}t=t->next[index];}return t->id>=0 ? t->id:t->id=color++; }int find(int x){if(ancestor[x]!=x){ancestor[x]=find(ancestor[x]);}return ancestor[x];}void unionSet(int x,int y){int px=find(x),py=find(y);ancestor[py]=px;}int main(){color=0;memset(degree,0,sizeof degree);for(int i=0;i<MAXN*2;++i) ancestor[i]=i;char c1[12],c2[12];while(cin>>c1>>c2){int x=getID(c1),y=getID(c2);unionSet(x,y);degree[x]++; degree[y]++;}int r=find(1),sum=0;for(int i=0;i<color;++i){if(degree[i]&1) sum++;if(find(i)!=r){cout<<"Impossible\n";return 0;}if(sum>2){cout<<"Impossible\n";return 0;}}if(sum==1) cout<<"Impossible\n";else cout<<"Possible\n";return 0;}
0 0
- POJ 2513 Colored Sticks <trie+并查集+欧拉路径>
- POJ 2513 Colored Sticks(Trie+并查集+欧拉回路)
- poj 2513 -- Colored Sticks ( Trie + 并查集 + 欧拉 )
- Poj 2513 Colored Sticks//Trie+并查集+欧拉通路
- POJ 2513 Colored Sticks(trie 欧拉通路 并查集)
- POJ 2513 Colored Sticks(欧拉回路判断+字典树Trie+并查集)
- [ACM] POJ 2513 Colored Sticks (Trie树,欧拉通路,并查集)
- poj 2513 Colored Sticks(trie+并查集+欧拉通路)
- POJ 2513 Colored Sticks (并查集 Trie树 欧拉回路)
- POJ 2513 Colored Sticks (Trie字典树+欧拉通路+并查集) 解题报告
- POJ 2513 Colored Sticks (Trie树,欧拉通路,并查集)
- poj-2513-Colored Sticks-字典树trie / hash +并查集 欧拉回路
- POJ 2513-Colored Sticks(连接木棍-trie树+并查集+欧拉通路)
- POJ 2513 Colored Sticks (Trie + 并查集 + 欧拉通路)
- poj 2513 Colored Sticks(字典树+欧拉路径+并查集)
- POJ 2513 Colored Sticks (字典树,并查集,欧拉路径组合题)
- poj 2513 Colored Sticks(欧拉回路 并查集 路径压缩 字典树)(困难)
- POJ-2513 Colored Sticks【并查集+Trie+欧拉路】
- 网络原因造成 spark task 卡住
- 语义分割输出结果上采样过程中的zoom value问题
- 第5章 进化式需求
- mysql数据类型整理
- 在mysql命令行中输入字符串提示 Incorrect string value: '\xC4\xE3' for column 'name' 出现异常
- POJ 2513 Colored Sticks <trie+并查集+欧拉路径>
- 14.05
- 进程间的通信方式——pipe(管道)
- Android内存优化
- Javaweb或javaEE完整项目名及包名、资源名命名规则
- 使用jQuery+PHP+Mysql实现抽奖程序
- declare命令
- Servlet生命周期
- JavaScript中Array.sort()的底层实现及应用