#include #include #include #include #include using namespace std; struct _l { int h[60]; int h_len; } linky[1005]; int L; struct _z { int t[2]; struct _zfoo { int lin; int deltahere; int deltawhere; int w; } z[103]; int z_len; char n[40]; } z[1005]; int Z; template class _pq : public priority_queue { public: void clear() { this->c.clear(); } }; struct event { event(int t,char w,short whe,short l) : time(t), who(w), where(whe), linka(l) {} int time; char who; short where; short linka; bool operator<(const event& e) const { return time > e.time; } }; map znames; int znames_len; _pq pq; int main(void) { next: while (scanf("%d", &L), L>=0) { znames.clear(); znames_len=0; pq.clear(); char tmp[50]; for (int l=0;l::iterator it=znames.find(tmp); if (it==znames.end()) { znames.insert(pair(tmp, znames_len)); zas=znames_len++; z[zas].z_len=0; z[zas].t[0]=z[zas].t[1]=-1; strcpy(z[zas].n, tmp); } else zas=it->second; if (last_zas!=-1) { _z *ptr=z+last_zas; ptr->z[ptr->z_len].lin=l; ptr->z[ptr->z_len].deltahere=totd2; ptr->z[ptr->z_len].deltawhere=totd; ptr->z[ptr->z_len++].w=zas; } if (d==-1) break; last_zas=zas; totd2=totd; totd+=d; } scanf("%d", &linky[l].h_len); for (int h=0;h::iterator it=znames.find(tmp); if (it==znames.end()) { if (j==1) { puts("No connection"); goto next;} int t3, t4; char tmp2[70]; scanf("%d:%d%s", &t3, &t4, tmp2); if (strcmp(tmp, tmp2)) { puts("No connection"); goto next;} if (t1*60+t2 < t3*60+t4) printf("%d:%02d\n", t3,t4); else printf("%d:%02d\n", t1,t2); goto next; } MARK(t1*60+t2, j, it->second, -1) } while(!pq.empty()) { event e=pq.top(); pq.pop(); if (z[e.where].t[1-e.who]>=0 && z[e.where].t[1-e.who] <= e.time) {printf("%d:%02d\n", ((e.time)/60)%24, (e.time)%60); goto next;} _z *zast=z+e.where; for (int i=0;iz_len;i++) { int kam=zast->z[i].w; int d=zast->z[i].deltahere; _l *lptr=linky+zast->z[i].lin; int acttime=e.time+(( (zast->z[i].lin != e.linka) && (e.linka!=-1)) ? 2 : 0); int *ptr=lower_bound(lptr->h, lptr->h+lptr->h_len, (acttime+60-d)%60); if (ptr==lptr->h+lptr->h_len) ptr=lptr->h; int nt=(acttime/60)*60+(*ptr+zast->z[i].deltahere)%60; while (nt < acttime) nt+=60; nt+=zast->z[i].deltawhere-zast->z[i].deltahere; if (z[kam].t[e.who]>=0 && z[kam].t[e.who] < nt) continue; // printf("%s->%s link %d arr %d:%d, %d %d\n", z[e.where].n, z[kam].n, zast->z[i].lin, nt/60, nt%60, acttime-e.time, d); MARK(nt, e.who, kam, zast->z[i].lin) } } puts("No connection"); } return 0; }