poj 2513(字典树等部分借鉴网上代码)
来源:互联网 发布:冷暴力孩子知乎 编辑:程序博客网 时间:2024/05/16 14:07
#include <iostream>#include<string>#include<iomanip>#include<cstdlib>#include<string.h>#include<malloc.h>using namespace std;int color=0;int ans[500010];int deg[500010]={0};class Tritree{public:int id;bool isword;Tritree *next[26];Tritree(){int i;isword=false;memset(next,0,sizeof(next));}}root;int insert(char *str){int i,j=0,md;Tritree *p=&root,*q;for(i=0;i<strlen(str);i++){md=str[i]-'a';if(p->next[md]==NULL){q=new Tritree;p->next[md]=q;p=p->next[md];}elsep=p->next[md];if(i==strlen(str)-1){if(!p->isword){p->isword=true;p->id=color++;}}}return p->id;}void unTritree(){for(int i=0;i<26;i++)if(root.next[i]!=NULL)free(root.next[i]);}int find(int m){if(ans[m]!=m)ans[m]=find(ans[m]);return ans[m];}void hand(int a,int b){int i,j;i=find(a);j=find(b);ans[i]=j;}int main(){int i,j,re,num=0;char a[11],b[11];for(i=0;i<500010;i++)ans[i]=i;while(cin>>a>>b){i=insert(a);deg[i]++;j=insert(b);deg[j]++;hand(i,j);}re=find(0);for(i=0;i<color;i++){if(find(i)!=re){cout<<"Impossible"<<endl;unTritree();return 0;}}for(i=0;i<color;i++){if(deg[i]%2)num++;}if(num==0||num==2)cout<<"Possible"<<endl;elsecout<<"Impossible"<<endl;unTritree();return 0;}
0 0
- poj 2513(字典树等部分借鉴网上代码)
- 个人借鉴网上爬虫代码改写的py
- POJ 2513 字典树
- 【数据结构与算法】 利用哈夫曼树进行文件压缩 (部分借鉴网上内容)
- trie 字典树 POJ 2513
- 参考了 网上 部分 代码 单链表
- 字典树、字典树代码
- poj 2513 Colored Sticks 字典树
- POJ 2513 Colored Sticks 欧拉路+字典树
- poj 2513 字典树+并查集
- POJ 2513 字典树+一笔画问题
- Colored Sticks poj 2513 字典树
- POJ 2513-Colored Sticks (字典树)
- POJ 2001 字典树
- 字典树 poj 2001
- POJ 3630 字典树
- POJ 1451 字典树
- POJ 2001 字典树
- Android Studio模板之文件组
- 【杭电2824】欧拉函数
- echarts中如何使用timeline组件
- static关键字注意事项
- Android随笔之动态加载布局
- poj 2513(字典树等部分借鉴网上代码)
- python——配置环境变量
- string类
- 在代码段中使用数据(0601)
- Opencv 和 c++ 框出图片中的目标
- leetcode 504. Base 7 python
- 保镖(hall定理&&集合动规&&优化)
- MyBatis缓存
- PAT (Advanced Level) 1004. Counting Leaves (30)