poj2513Colored Sticks
来源:互联网 发布:photoshop cc mac版 编辑:程序博客网 时间:2024/05/21 09:28
#include<stdio.h>#include<string.h>#include<stdlib.h>int p[500005],rank[500005],degree[500005],sum,num=0;char a[15],b[15];typedef struct node{int key;struct node *next[26];}trie;trie *root;int n,m;void init(){for(int i=0;i<=500100;i++){p[i]=i;rank[i]=0;degree[i]=0;}}int find(int x){if(x==p[x]) return x;return p[x]=find(p[x]);}void combine(int a,int b){if(a==b) return; if(rank[a]>rank[b]) p[b]=a; else{ if(rank[a]==rank[b]) rank[b]++; p[a]=b; }}trie *New(){int i,k;trie *p;p=(trie*)malloc(sizeof(trie));p->key=-1;for(i=0;i<26;i++){p->next[i]=NULL;}return p;}int Insert(trie*root,char*s){int i,k;trie *p=root;i=0;while(s[i]){k=s[i++]-'a';if(p->next[k]==NULL) p->next[k]=New();p=p->next[k];}if(p->key==-1) p->key=++num;return p->key;}int main(){int i,j,k,x,y;init();root=New();while(scanf("%s%s",a,b)!=EOF){x=Insert(root,a);y=Insert(root,b);degree[x]++,degree[y]++;combine(find(x),find(y));}sum=0;for(i=1;i<num;i++) if(degree[i]%2) sum++;if(sum>2) printf("Impossible\n");else{for(i=2;i<num;i++){if(find(i)!=find(1)){printf("Impossible\n");return 0;}}printf("Possible\n");}return 0;}
0 0
- poj2513Colored Sticks
- POJ2513Colored Sticks一笔画问题
- poj2513Colored Sticks trie+merge_set+Eular
- poj2513Colored Sticks(欧拉通路+字典树+并查集)
- poj2513Colored Sticks(快排-二分-并查集-欧拉路)
- Sticks
- sticks
- sticks
- sticks
- Sticks
- sticks
- Sticks
- Sticks
- Sticks
- Sticks
- Sticks
- Sticks
- Sticks
- hdu 4950 Monster (数学思维)
- 异常说明符
- HTTP的KeepAlive是开启还是关闭?
- 67_跳转函数
- iOS中 远程推送简单介绍
- poj2513Colored Sticks
- 68_排序函数
- 护肝养肝就选甘道新甘泰保健茶随州市万松堂康汇招代理
- 抓住所有处理程序
- hdu 1285(拓扑排序)
- UVA 10622 - Perfect P-th Powers
- flex里itemRenderer和itemEditor区别
- ASP.NET通用权限组件思路设计
- 关于网站备案的44个问题