#include using namespace std; typedef int64_t Time; struct Flight; struct Airport; constexpr Time infinity=1ll<<60ll; struct Flight{ Time s; Time t; Airport *from; Airport *dest; int id; bool operator<(Flight const &a)const{ return s!=a.s? s edges; }; Airport *get_airport(string name){ static map existent; if (not existent.count(name)){ return existent[name]=new Airport{name,{}}; }else{ return existent[name]; } } Time parse_time(string s){ Time res=0; stringstream ss(s); assert(getline(ss,s,'d')); res=res+stoi(s); assert(getline(ss,s,':')); res=res*24+stoi(s); assert(getline(ss,s,':')); res=res*60+stoi(s); return res; } Time dijkstra(Airport *source,Time st,Airport *sink){ map at={{source,st}}; priority_queue,vector>,greater>> todo; todo.push({st,source}); while (not todo.empty()){ Time w=todo.top().first; Airport *a=todo.top().second; //cerr<<" go "<name<<" @ "<edges){ if (e.s>=w and (not at.count(e.dest) or e.tedges.insert(all_flights.back()); } int64_t ideal=0,worst=0; int n; cin>>n; vector my_flights(n); for (auto &i: my_flights){ int id; cin>>id; --id; i=all_flights[id]; ideal=max(ideal,i.t); } //cerr<<" n = "<edges.erase(i); worst=max(worst,dijkstra(i.from,i.s,my_flights.back().dest)); i.from->edges.insert(i); } if (worst==infinity){ cout<<"stranded"<