1 #include <iostream> 2 #include <cstdio> 3 #include <map> 4 #include <cstring> 5 6 using namespace std; 7 8 struct edge 9 { 10 int fro,to,val; 11 }e[30000]; 12 int ednum=0; 13 int div[3000]; 14 int MAX=1<<29; 15 map<string ,int>mp; 16 17 void addEdge(int _fro,int _to,int _val) 18 { 19 e[ednum].fro=_fro; 20 e[ednum].to=_to; 21 e[ednum].val=_val; 22 ednum++; 23 } 24 25 int main() 26 { 27 int T; 28 scanf("%d",&T); 29 for(int l=1;l<=T;l++) 30 { 31 int n; 32 scanf("%d",&n); 33 mp.clear(); 34 string a,b; 35 int c,d; 36 int num=0; 37 ednum=0; 38 for(int i=1;i<=n;i++) 39 { 40 cin>>a>>b>>c>>d; 41 if(mp.find(a)==mp.end()) 42 { 43 mp[a]=num; 44 num++; 45 } 46 if(mp.find(b)==mp.end()) 47 { 48 mp[b]=num; 49 num++; 50 } 51 c=(c+6)%24; 52 int tmp=(d+c)%24; 53 if((c>12&&c<24)||(tmp>12&&tmp<24)||(d>12)) 54 continue; 55 addEdge(mp[a]*24+c,mp[b]*24+tmp,0); 56 } 57 string start,en; 58 cin>>start>>en; 59 for(int i=0;i<num;i++) 60 { 61 for(int j=0;j<24;j++) 62 { 63 if(j!=17) 64 addEdge(i*24+j,i*24+((j+1)%24),0); 65 else 66 addEdge(i*24+j,i*24+((j+1)%24),1); 67 } 68 } 69 for(int i=0;i<num*24;i++) 70 { 71 div[i]=MAX; 72 } 73 div[mp[start]*24]=0; 74 for(int i=0;i<num*24;i++) 75 { 76 for(int j=0;j<ednum;j++) 77 { 78 79 if(div[e[j].to]>div[e[j].fro]+e[j].val) 80 div[e[j].to]=div[e[j].fro]+e[j].val; 81 } 82 } 83 int mi=MAX; 84 for(int i=0;i<23;i++) 85 { 86 if(div[mp[en]*24+i]<mi) 87 mi=div[mp[en]*24+i]; 88 } 89 cout<<"Test Case "<<l<<"."<<endl; 90 if(mi>=MAX) 91 cout<<"There is no route Vladimir can take."<<endl; 92 else 93 cout<<"Vladimir needs "<<mi<<" litre(s) of blood."<<endl; 94 } 95 return 0; 96 }