#include #include #include #include #include #include #include #include using namespace std; const int INF = -1e9; const int TIME_MIN = 6 * 60; const int TIME_MAX = 21 * 60; struct City { int id; long long x, y, w; }; struct Flight { int from, to, s, t; }; int to_min(int h, int m) { return h * 60 + m; } int calc_dur(const City& a, const City& b) { double d = sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)); return (int)ceil((60.0 * d / 800.0 + 40.0) / 5.0) * 5; } class Solver { int N, M, K; double R; vector cities; vector sq_flights; int s_sq[48][48][22]; vector> schedule; public: void solve() { if (!(cin >> N >> R)) return; cities.resize(N); for (int i = 0; i < N; ++i) { cities[i].id = i + 1; cin >> cities[i].x >> cities[i].y >> cities[i].w; } cin >> M; for (int i = 0; i < M; ++i) { int a, b, sh, sm, th, tm; char c; if (!(cin >> a >> sh >> c >> sm >> b >> th >> c >> tm)) break; sq_flights.push_back({a, b, to_min(sh, sm), to_min(th, tm)}); } cin >> K; for(int i=1; i<=N; ++i) for(int j=1; j<=N; ++j) for(int t=0; t<21; ++t) s_sq[i][j][t] = INF; for(int ti=0; ti<21; ++ti) { int target_t = to_min(11, 0) + ti * 30; for(int j=1; j<=N; ++j) { s_sq[j][j][ti] = target_t; bool updated = true; int cnt = 0; while(updated && cnt < N) { updated = false; for(auto& f : sq_flights) { if (f.t <= s_sq[f.to][j][ti]) { if (f.s > s_sq[f.from][j][ti]) { s_sq[f.from][j][ti] = f.s; updated = true; } } } cnt++; } } } schedule.resize(K); mt19937 engine(42); for(int k=0; k TIME_MAX) break; schedule[k].push_back({cur_c, nxt_c, cur_t, cur_t + d}); cur_t += d; cur_c = nxt_c; } } auto start_time = chrono::system_clock::now(); while (true) { auto now = chrono::system_clock::now(); if (chrono::duration_cast(now - start_time).count() > 800) break; int k = engine() % K; if (schedule[k].empty()) continue; int f_idx = engine() % (int)schedule[k].size(); int old_to = schedule[k][f_idx].to; int new_to = (engine() % N) + 1; if (new_to == schedule[k][f_idx].from) continue; int new_dur = calc_dur(cities[schedule[k][f_idx].from-1], cities[new_to-1]); int new_t = schedule[k][f_idx].s + new_dur; if (new_t <= TIME_MAX) { bool ok = true; if (f_idx < (int)schedule[k].size() - 1) { if (new_t > schedule[k][f_idx+1].s || new_to != schedule[k][f_idx+1].from) ok = false; } if (ok) { schedule[k][f_idx].to = new_to; schedule[k][f_idx].t = new_t; } } } for (int k = 0; k < K; ++k) { printf("%d\n", (int)schedule[k].size()); for (auto& f : schedule[k]) { printf("%d %02d:%02d %d %02d:%02d\n", f.from, f.s/60, f.s%60, f.to, f.t/60, f.t%60); } } } }; int main() { Solver s; s.solve(); return 0; }