#include #include #include #include #include using namespace std; struct City { int x, y; long long w; }; struct Flight { int a, s, b, t; }; static constexpr int DAY_START = 6 * 60; // 06:00 static constexpr int DAY_END = 21 * 60; // 21:00 int calc_duration_minutes(const City& c1, const City& c2) { long double dx = (long double)c1.x - (long double)c2.x; long double dy = (long double)c1.y - (long double)c2.y; long double d = sqrtl(dx * dx + dy * dy); long double raw = 60.0L * d / 800.0L + 40.0L; long double slots = ceill((raw - 1e-12L) / 5.0L); int dur = (int)(slots * 5.0L); return dur; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, R; cin >> N >> R; vector cities(N); for (int i = 0; i < N; ++i) { cin >> cities[i].x >> cities[i].y >> cities[i].w; } int M; cin >> M; for (int i = 0; i < M; ++i) { int a, s, b, t; cin >> a >> s >> b >> t; (void)a; (void)s; (void)b; (void)t; } int K; cin >> K; vector> dur(N, vector(N, 0)); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (i == j) continue; dur[i][j] = calc_duration_minutes(cities[i], cities[j]); } } // Greedy hub selection: prioritize large population and short average travel time to others. int hub = 0; long double bestHubScore = -1.0L; for (int h = 0; h < N; ++h) { long double acc = 0.0L; for (int j = 0; j < N; ++j) { if (j == h) continue; acc += (long double)cities[j].w / (long double)dur[h][j]; } long double score = acc * (long double)cities[h].w; if (score > bestHubScore) { bestHubScore = score; hub = h; } } // Greedy spoke ordering: heavy population + short cycle time gets priority. vector> cand; cand.reserve(max(0, N - 1)); for (int v = 0; v < N; ++v) { if (v == hub) continue; long double score = (long double)cities[v].w / (long double)dur[hub][v]; cand.push_back({score, v}); } sort(cand.begin(), cand.end(), [&](const auto& lhs, const auto& rhs) { if (lhs.first != rhs.first) return lhs.first > rhs.first; return lhs.second < rhs.second; }); vector assigned(K, hub); if (!cand.empty()) { for (int i = 0; i < K; ++i) { assigned[i] = cand[i % (int)cand.size()].second; } } else { // Degenerate fallback (should not happen under official constraints). for (int i = 0; i < K; ++i) assigned[i] = (hub + 1) % N; } vector> ans(K); // Build simple shuttle schedules with staggered phases/orientations. for (int p = 0; p < K; ++p) { int spoke = assigned[p]; int phase = (p % 6) * 5; // 0,5,...,25 (fits 30-min scoring grid diversification) bool startFromHub = (p % 2 == 0); // alternate directions int curCity = startFromHub ? hub : spoke; int curTime = DAY_START + phase; while (true) { int nxtCity = (curCity == hub ? spoke : hub); int t = curTime + dur[curCity][nxtCity]; if (t > DAY_END) break; ans[p].push_back(Flight{curCity + 1, curTime, nxtCity + 1, t}); curCity = nxtCity; curTime = t; // no turnaround time required } } for (int i = 0; i < K; ++i) { cout << ans[i].size() << '\n'; for (const auto& f : ans[i]) { cout << f.a << ' ' << f.s << ' ' << f.b << ' ' << f.t << '\n'; } } return 0; }