//TRIE + 并查集 + 欧拉回路 //A了这道题,学会了用并查集判断无向图的连通性 #include<iostream> #include<map> #include<string> using namespace std; const int MAX = 500003; int N; int fa[MAX]; int deg[MAX]; struct trie { int color; trie *next[26]; trie() { color = 0; memset(next,0,sizeof(next)); } }*root; int insert(trie *p,char str[]) { for(int i = 0;i < strlen(str);++i) { int s = str[i] - 'a'; if(p->next[s] == NULL) p->next[s] = new trie; p = p->next[s]; if(i == strlen(str) - 1) { if(p->color == 0) p->color = ++N; ++deg[p->color]; return p->color; } } } void init() { for(int i = 1;i <= MAX;++i) fa[i] = i; } int Find(int x) { if(x == fa[x]) return x; else return fa[x] = Find(fa[x]); } void Union(int x,int y) { x = Find(x); y = Find(y); fa[x] = y; } bool isConnected() { for(int i = 2;i <= N;++i) if(Find(i) != Find(i-1)) return false; return true; } int main() { //freopen("in.txt","r",stdin); char c1[11],c2[11]; bool ok = 1; int x,y,oddDeg = 0; N = 0; root = new trie; memset(deg,0,sizeof(deg)); init(); while(scanf("%s%s",c1,c2) != EOF) { x = insert(root,c1); y = insert(root,c2); Union(x,y); } if(!isConnected()) { printf("Impossible/n"); return 0; } for(int i = 1;i <= N;++i) { if(deg[i] % 2 != 0) ++oddDeg; if(oddDeg > 2) { printf("Impossible/n"); return 0; } } printf("Possible/n"); return 0; }