1
0

CodeForces-1245D.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include <iostream>
  2. #include <limits>
  3. #include <utility>
  4. #include <vector>
  5. using namespace std;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. int n; cin >> n;
  10. vector<long long> x(n), y(n), c(n), k(n);
  11. for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
  12. for (auto &v : c) cin >> v;
  13. for (auto &v : k) cin >> v;
  14. vector<long long> best = c;
  15. vector<int> parent(n, -1); vector<bool> used(n, false);
  16. vector<int> stations; vector<pair<int, int>> wires;
  17. long long total = 0;
  18. for (int step = 0; step < n; ++step) {
  19. int v = -1;
  20. for (int i = 0; i < n; ++i) if (!used[i] && (v == -1 || best[i] < best[v])) v = i;
  21. used[v] = true; total += best[v];
  22. if (parent[v] == -1) stations.push_back(v);
  23. else wires.push_back({v, parent[v]});
  24. for (int to = 0; to < n; ++to) if (!used[to]) {
  25. long long cost = (k[v] + k[to]) * (abs(x[v] - x[to]) + abs(y[v] - y[to]));
  26. if (cost < best[to]) best[to] = cost, parent[to] = v;
  27. }
  28. }
  29. cout << total << '\n' << stations.size() << '\n';
  30. for (int v : stations) cout << v + 1 << ' ';
  31. cout << '\n' << wires.size() << '\n';
  32. for (auto [u, v] : wires) cout << u + 1 << ' ' << v + 1 << '\n';
  33. }