POJ-2513(trie+并查集+欧拉回路)
来源:互联网 发布:2017淘宝儿童模特招聘 编辑:程序博客网 时间:2024/05/20 21:48
自认为此题有个bug
#define NUMBER 500005int p[NUMBER + 5];int rank[NUMBER + 5];void make_set(int x) {p[x] = x;rank[x] = 0;}int find_set(int x) {if (x != p[x]) p[x] = find_set(p[x]);return p[x];}void link_set(int x, int y) {if (rank[x] > rank[y]) p[y] = x;else {p[x] = y;if (rank[x] == rank[y]) ++rank[y];}}void union_set(int x, int y){link_set(find_set(x), find_set(y));}int Index;int degree[NUMBER];struct trie{ int cnt; trie *p[26];} * root;int make_tree(char *s){ trie * r = root; trie * tmp; int i, j; for (i = 0; s[i] != '\0'; ++i) { if (r->p[s[i] - 'a'] == NULL) { tmp = new trie; tmp->cnt = -1; for (j = 0; j < 26; ++j) tmp->p[j] = NULL; r->p[s[i] - 'a'] = tmp; } r = r->p[s[i] - 'a']; }if (r->cnt == -1)r->cnt = Index++;return r->cnt;}int main(){int i, j;root = new trie; for (i = 0; i < 26; ++i)root->p[i] = NULL;for (i = 0; i < NUMBER; ++i)make_set(i);char a[15], b[15];char s[1000];int flag = 0;while (gets(s) != NULL && flag == 0) {memset(degree, 0, sizeof(degree));for (i = 0; i < NUMBER; ++i)make_set(i);root = new trie; for (i = 0; i < 26; ++i)root->p[i] = NULL;Index = 0;while (strlen(s) != 0 && flag == 0) {sscanf(s, "%s %s", a, b);int x = make_tree(a);int y = make_tree(b);degree[x]++;degree[y]++;union_set(x, y);if (gets(s) == NULL)flag = 1;}int sum = 0;for (i = 0; i < Index; ++i) {if (degree[i] % 2 == 1)++sum;}if (sum == 0 || sum == 2) {int t = find_set(0);for (i = 1; i < Index; ++i) {if (find_set(i) != t) {break;}}if (i >= Index - 1) printf("Possible\n");///////////////////////////buggggggggggggggggggggggggggelse printf("Impossible\n");} else printf("Impossible\n");}return 0;}
- POJ-2513(trie+并查集+欧拉回路)
- poj 2513 trie树+并查集+欧拉回路
- POJ 2513 Colored Sticks(Trie+并查集+欧拉回路)
- POJ 2513 Colored Sticks(欧拉回路判断+字典树Trie+并查集)
- poj 2513 欧拉回路+并查集判断是否联通+Trie树
- POJ 2513 Colored Sticks (并查集 Trie树 欧拉回路)
- poj-2513-Colored Sticks-字典树trie / hash +并查集 欧拉回路
- POJ2513 Trie+并查集+欧拉回路
- Trie树+并查集+欧拉回路poj2513
- poj 2513 欧拉回路+并查集+字典树
- POJ 2513 欧拉通路+并查集+trie树
- POJ 2513 Colored Sticks(字典树+并查集连通性+欧拉回路)
- poj 2513 Colored Sticks 欧拉回路(字典树 +并查集)
- POJ 2513 Colored sticks(字典树 + 欧拉回路 + 并查集)
- POJ 题目2513 Colored Sticks(字典树+并查集+欧拉回路)
- POJ 2513 Colored Sticks(欧拉回路+字典树+并查集)
- POJ 2513(欧拉回路+ 并查集+字典树)
- poj 2513 Colored Sticks (字典树,并查集,欧拉回路)
- C#打包制作部署安装程序
- RFC及RFC编辑者
- [UIImage imageNamed:@"icon.png"] 加载图片的问题
- GPU通用计算调研报告
- sql 学生信息表S(sno,sname)
- POJ-2513(trie+并查集+欧拉回路)
- Visual Studio 2010 中CUDA 4.0的安装与配置
- 【树状数组】PKU-2057-The Lost House
- lpk.cpp
- script语法错误
- 数据结构之迷宫
- 使用NSOperation和NSOperationQueue启动多线程开发应用
- 一位老电子工程师十年的职场感悟
- 链表 逆序 例子