/* [NWERC'06] TICKET TO RIDE by: Jan Kuipers */ using namespace std; #include #include #include #include #include int N,M,nextID; map IDcache; vector > next,len; vector bit; int ID(string s) { if (IDcache.count(s)) return IDcache[s]; return IDcache[s]=nextID++; } int read () { cin>>N>>M; if (N==0 && M==0) return 0; string city; for (int i=0; i>city; next=len=vector >(N); nextID=0; IDcache.clear(); for (int i=0; i>city1>>city2>>L; int n1=ID(city1), n2=ID(city2); next[n1].push_back(n2); len [n1].push_back(L); next[n2].push_back(n1); len [n2].push_back(L); } bit=vector(N,0); for (int i=0; i<8; i++) { string city; cin>>city; bit[ID(city)]|=1< b.dist; } int solve () { vector > seen(N, vector(1<<8, 0)); vector > best(N, vector(1<<8, INT_MAX/2)); priority_queue pq; for (int i=0; i %i\n",n,mask,dist); for (int i=0; is.dist) { best[s.n][s.mask]s.dist) { best[s.n][s.mask] ii(4); for (ii[0]=0; ii[0]<4; ii[0]++) for (ii[1]=0; ii[1]<4; ii[1]++) for (ii[2]=0; ii[2]<4; ii[2]++) for (ii[3]=0; ii[3]<4; ii[3]++) { int tmp=0; for (int i=0; i<4; i++) { int mask=0; for (int j=0; j<4; j++) if (ii[j]==i) mask|=3<<2*j; if (mask==0) continue; int tmp2=INT_MAX/10; for (int n=0; n