欧拉回路+并查集(判断图的联通)+Tire树(快速查找字符串,并且记录相应点的度数)
Tire树相关知识
#includeusing namespace std;const int maxc = 26;const int maxn = 500001;struct TrieNode{ int key; TrieNode * child[maxc]; TrieNode() { key=-1; memset(child,0,sizeof(child)); }};int count[maxn];TrieNode * root;int tot=-1;int insert(char * s){ if(root==NULL) root=new TrieNode; int did; TrieNode * tem=root; for(;*s!='\0';s++) { did=*s-'a'; if(tem->child[did]==NULL) tem->child[did]=new TrieNode; tem=tem->child[did]; } if(tem->key==-1) tem->key=++tot; count[tem->key]++; return tem->key;}struct UFSTree{ int val; int parent; int rank;}t[maxn];void init(){ for(int i=0;i t[p2].rank) t[p2].parent=p1; else { t[p1].parent=p2; if(t[p1].rank==t[p2].rank) t[p2].rank++; }}int main(){ char f[11],s[11]; init(); while(scanf("%s %s",f,s)!=EOF) { int k1=insert(f); int k2=insert(s); int p1=find(k1); int p2=find(k2); if(p1!=p2) Union(p1,p2); } if(root==NULL) { cout<<"Possible"<