#include #include char d[26000][17]; int dp[26000]; int z; int n; struct adj{ int i; struct adj *next; }; struct adj *a[26000]; int q[26000]; int dist[26000]; compar(int *a, int *b){ int r; char at = d[*a][z]; char bt = d[*b][z]; if (at) d[*a][z] = '_'; if (bt) d[*b][z] = '_'; r = strcmp(d[*a],d[*b]); d[*a][z] = at; d[*b][z] = bt; return r; } main(){ int i,j,k,m; for(n=0;;n++){ gets(d[n]); if (!d[n][0]) break; } for (i=0;ii = dp[j]; t->next = a[dp[i]]; a[dp[i]] = t; t = (struct adj *)malloc(sizeof(struct adj)); t->i = dp[i]; t->next = a[dp[j]]; a[dp[j]] = t; }else break; } } } for (m=0;;m++){ int i1, i2; char w1[20], w2[20]; int qn; if (2 != scanf(" %s %s",w1,w2)) break; if (m) printf("\n"); for (i1=0;i1next) { if (dist[p->i] == 999999) { dist[p->i] = dist[q[i]] + 1; q[qn++] = p->i; } } } if (i1 != n && i2 != n && dist[i1] != 999999) { int this = i1; printf("%s\n",w1); while (this != i2) { struct adj *p; for (p=a[this];p && dist[p->i] != dist[this]-1;p=p->next){} this = p->i; printf("%s\n",d[this]); } }else printf("No solution.\n"); } }