#include #include #include #include #include #include #include #include using namespace std; const int TIME_MIN = 6 * 60; const int TIME_MAX = 21 * 60; const int TARGET_START = 11 * 60; const int TARGET_END = 21 * 60; const int TARGET_STEP = 30; struct City { int id; long long x, y, w; }; struct Flight { int from, to, s, t; }; inline 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 get_latest_departure_all(const vector& all_flights, int dst, int target) { vector best(N, -1e9); best[dst] = target; for (int i = (int)all_flights.size() - 1; i >= 0; --i) { const auto& f = all_flights[i]; if (f.t <= best[f.to] && f.s > best[f.from]) { best[f.from] = f.s; } } return best; } long long evaluate_config(const vector& flights) { if (flights.empty()) return -1; vector sorted_f = flights; sort(sorted_f.begin(), sorted_f.end(), [](const Flight& a, const Flight& b){ return a.s < b.s; }); long long total_v = 0; for (int dst = 0; dst < N; ++dst) { for (int target = TARGET_START; target <= TARGET_END; target += TARGET_STEP) { vector ci_dep = get_latest_departure_all(sorted_f, dst, target); for (int src = 0; src < N; ++src) { if (src == dst) continue; double dx = cities[src].x - cities[dst].x, dy = cities[src].y - cities[dst].y; if (sqrt(dx*dx + dy*dy) < 0.25 * R) continue; if (ci_dep[src] > TIME_MIN) total_v += cities[src].w * cities[dst].w; } } } return total_v; } public: void solve() { auto start_time = chrono::system_clock::now(); if (!(cin >> N >> R)) return; cities.resize(N); for (int i = 0; i < N; ++i) { cities[i].id = i; 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; cin >> a >> sh >> c >> sm >> b >> th >> c >> tm; } cin >> K; vector> pop_rank; for(int i=0; i> best_schedule(K); auto check_and_update = [&](const vector>& current_sched) { vector all_f; for(auto& vk : current_sched) for(auto& f : vk) all_f.push_back(f); long long sc = evaluate_config(all_f); if (sc > best_total_score) { best_total_score = sc; best_schedule = current_sched; } }; for (int i = 0; i < min(N, 4); ++i) { int h = pop_rank[i].second; vector spokes; for(auto& p : pop_rank) { if(p.second == h) continue; double dx = cities[h].x - cities[p.second].x, dy = cities[h].y - cities[p.second].y; if(sqrt(dx*dx + dy*dy) >= 0.25 * R) spokes.push_back(p.second); } if (spokes.empty()) continue; vector> current(K); for (int k = 0; k < K; ++k) { int v = spokes[k % spokes.size()]; int cur_t = TIME_MIN + (k % 6) * 5, cur_loc = h, d = calc_dur(cities[h], cities[v]); while (cur_t + d <= TIME_MAX) { int dest = (cur_loc == h) ? v : h; current[k].push_back({cur_loc, dest, cur_t, cur_t + d}); cur_t += d; cur_loc = dest; } } check_and_update(current); } for (int i = 0; i < min(N, 3); ++i) { for (int j = i + 1; j < min(N, 3); ++j) { int h1 = pop_rank[i].second, h2 = pop_rank[j].second; double dh = sqrt(pow(cities[h1].x-cities[h2].x, 2) + pow(cities[h1].y-cities[h2].y, 2)); if(dh < 0.25 * R) continue; vector> current(K); for(int k=0; k> current(K); for(int k=0; k(chrono::system_clock::now() - start_time).count() < 950) { int k = engine() % K; if (best_schedule[k].empty()) continue; int f_idx = engine() % best_schedule[k].size(); int diff = (engine() % 2 == 0 ? 5 : -5); int ps = best_schedule[k][f_idx].s, pt = best_schedule[k][f_idx].t; int ns = ps + diff, nt = pt + diff; if (ns >= TIME_MIN && nt <= TIME_MAX) { if ((f_idx == 0 || best_schedule[k][f_idx-1].t <= ns) && (f_idx == (int)best_schedule[k].size()-1 || nt <= best_schedule[k][f_idx+1].s)) { long long old_sc = best_total_score; best_schedule[k][f_idx].s = ns; best_schedule[k][f_idx].t = nt; vector all_f; for(auto& vk : best_schedule) for(auto& f : vk) all_f.push_back(f); long long new_sc = evaluate_config(all_f); if (new_sc >= old_sc) best_total_score = new_sc; else { best_schedule[k][f_idx].s = ps; best_schedule[k][f_idx].t = pt; } } } } for (int k = 0; k < K; ++k) { printf("%d\n", (int)best_schedule[k].size()); for (auto& f : best_schedule[k]) printf("%d %02d:%02d %d %02d:%02d\n", f.from + 1, f.s/60, f.s%60, f.to + 1, f.t/60, f.t%60); } } }; int main() { Solver().solve(); return 0; }