Each word is adjacent to two letters, cannot be a vowel or consonant at the same time, must have five vowels ...
Various poses can be over: 7 FOR,DP, black and white stained, DFS, and check ....
The main idea is that the adjacent letter is connected to the edge
See how slow str = str + STR2
#include <bits/stdc++.h>using namespacestd;#definePB push_backintcolor[ -];intg[ -][ -];Const intMAXN = 1e5+5;CharS[MAXN];BOOLvis[ -];Charmp[ -];BOOLBipartite (intu) { for(intv =0; V < -; v++)if(G[u][v]) {if(Color[v] = = Color[u])return false; if(!Color[v]) {Color[v]=3-Color[u]; if(!bipartite (v))return false; } } return true;}Chartab[5] = {'A','E','I','O','U'};intTsz =0, TSZ2 =0;Chartab2[ +] = {'B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Y','Z'};vector<string>Word;vector<int> bcc[ -][2];intbcnt;BOOLDfsintDintCurints) { if(d = =bcnt) { if(cur = =5){ for(inti =0; i < bcnt; i++) {vector<int> &v = bcc[i][(s>>i) &1]; for(intj =0; J < V.size (); J + +) {Mp[v[j]]= tab[tsz++]; } } return true; } return false; } if(Dfs (d+1, cur+bcc[d][0].size (), s) | | DFS (d+1, cur+bcc[d][1].size (), s| (1<<D)))return true; return false;}intMain () {//freopen ("In.txt", "R", stdin);Freopen ("javanese.in","R", stdin); Freopen ("Javanese.out","W", stdout); while(~SCANF ("%s", s)) {Word. PB (s); for(inti =1; S[i]; i++){ intU = s[i]-'A', V = s[i-1] -'A'; G[U][V]= G[v][u] =1; } } for(inti =0; I < -; i++)if(!Color[i]) {Color[i]=1; if(!bipartite (i)) {Puts ("Impossible");return 0; } for(inti =0; I < -; i++)if(color[i]&&!Vis[i]) {Vis[i]=true; Bcc[bcnt][color[i]-1]. PB (i); } bcnt++; } if(!dfs (0,0,0) {puts ("Impossible"); } Else { for(inti =0; I < -; i++)if(!mp[i]) mp[i] = tab2[tsz2++]; for(intj =0; J < Word.size (); J + +){ if(j) Putchar (' '); string& str =Word[j]; for(inti =0; I < str.size (); i++){ if('A'<=str[i]&&str[i]<='Z') Putchar (Mp[str[i]-'A']); ElsePutchar (Str[i]); }} putchar ('\ n'); } return 0;}
Codeforces Gym 100286J Javanese cryptoanalysis