Test instructions: For the given graph, the nodes with the least bandwidth are arranged.
Analysis: The number of nodes is up to 8, all arranged. The vertex range is a~z.
#pragmaComment (linker, "/stack:102400000, 102400000")#include<cstdio>#include<cstring>#include<cstdlib>#include<cctype>#include<cmath>#include<iostream>#include<sstream>#include<iterator>#include<algorithm>#include<string>#include<vector>#include<Set>#include<map>#include<stack>#include<deque>#include<queue>#include<list>#defineMin (A, B) ((a < b) a:b)#defineMax (A, B) ((a < b)? b:a)typedefLong Longll;typedef unsignedLong LongLlu;Const intInt_inf =0x3f3f3f3f;Const intInt_m_inf =0x7f7f7f7f;Constll ll_inf =0x3f3f3f3f3f3f3f3f;Constll ll_m_inf =0x7f7f7f7f7f7f7f7f;Const intDr[] = {0,0, -1,1, -1, -1,1,1};Const intDc[] = {-1,1,0,0, -1,1, -1,1};Const intMOD = 1e9 +7;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMAXN = -+Ten;Const intMaxt =10000+Ten;using namespacestd;CharS[MAXN];Set<int> node[ -];vector<int>v;intt[Ten];voidinit () { for(inti =0; I < -; ++i) {node[i].clear (); } v.clear (); memset (T,0,sizeoft); intLen =strlen (s); for(inti =0; i < Len; ++i) { if(S[i] = =':'){ intTMP = S[i-1] -'A'; while(1){ ++i; if(i = = len) Break; if(S[i] = =';') Break; Node[tmp].insert (S[i]-'A'); Node[s[i]-'A'].insert (TMP); } } }}intMain () { while(SCANF ("%s", s) = =1){ if(s[0] =='#')return 0; Init (); for(inti =0; I < -; ++i) { if(Node[i].size ()) {v.push_back (i); } } intLen =v.size (); intAns =Int_m_inf; Do{ intTMP =0; for(inti =0; i < Len; ++i) { for(intj =0; J < I; ++j) { if(Node[v[i]].count (V[j])) {tmp= MAX (tmp, I-j); } } } if(TMP <ans) {ans=tmp; for(inti =0; i < Len; ++i) {T[i]=V[i]; } } } while(Next_permutation (V.begin (), V.end ())); for(inti =0; i < Len; ++i) {printf ("%c",'A'+T[i]); } printf ("%d\n", ans); } return 0;}
UVA-140 Bandwidth (bandwidth) (full array)