#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(vector& flights) { sort(flights.begin(), flights.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(flights, 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() { if (!(cin >> N >> R)) return; cities.resize(N); for (int i = 0; i < N; ++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 start_time = chrono::system_clock::now(); for (int i = 0; i < min(N, 5); ++i) { int h = pop_rank[i].second; vector spokes; for(auto& p : pop_rank) { if(p.second == h) continue; double dx = cities[h-1].x - cities[p.second-1].x, dy = cities[h-1].y - cities[p.second-1].y; if(sqrt(dx*dx + dy*dy) >= 0.25 * R) spokes.push_back(p.second); } if (spokes.empty()) continue; vector> current_sched(K); vector all_f; for (int k = 0; k < K; ++k) { int v = spokes[k % spokes.size()]; int cur_t = TIME_MIN, cur_loc = h, d = calc_dur(cities[h-1], cities[v-1]); while (cur_t + d <= TIME_MAX) { int dest = (cur_loc == h) ? v : h; current_sched[k].push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d}); all_f.push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d}); cur_t += d; cur_loc = dest; } } 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, 3); ++i) { for (int j = i + 1; j < min(N, 3); ++j) { int h1 = pop_rank[i].second, h2 = pop_rank[j].second; double dxh = cities[h1-1].x - cities[h2-1].x, dyh = cities[h1-1].y - cities[h2-1].y; if(sqrt(dxh*dxh + dyh*dyh) < 0.25 * R) continue; vector> current_sched(K); vector all_f; for (int k = 0; k < K; ++k) { int u, v; if (k < 4) { u = h1; v = h2; } else { u = (k % 2 == 0) ? h1 : h2; v = pop_rank[(k / 2) % N + 1].second; // 簡易割り当て if (v == h1 || v == h2) v = pop_rank[0].second == u ? pop_rank[1].second : pop_rank[0].second; } int cur_t = TIME_MIN, cur_loc = u, d = calc_dur(cities[u-1], cities[v-1]); while (cur_t + d <= TIME_MAX) { int dest = (cur_loc == u) ? v : u; current_sched[k].push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d}); all_f.push_back({cur_loc - 1, dest - 1, cur_t, cur_t + d}); cur_t += d; cur_loc = dest; } } long long sc = evaluate_config(all_f); if (sc > best_total_score) { best_total_score = sc; best_schedule = current_sched; } } } 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; }