Georgiy031

Untitled

Jun 12th, 2020
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.    
  9.     int n, m;
  10.     cin >> n >> m;
  11.     vector<int> I(m), J(m), C(m);
  12.     for (int i = 0; i < m; ++i) {
  13.         cin >> I[i];
  14.     }
  15.     for (int i = 0; i < m; ++i) {
  16.         cin >> J[i];
  17.     }
  18.     for (int i = 0; i < m; ++i) {
  19.         cin >> C[i];
  20.     }
  21.  
  22.     vector<int> H(n, -1), L(m, -1);
  23.     for (int k = 0; k < m; ++k) {
  24.         int j = J[k];
  25.         L[k] = H[j];
  26.         H[j] = k;
  27.     }
  28.     cout << "H: ";
  29.     for (auto x : H) {
  30.         cout << x << " ";
  31.     }
  32.     cout << endl;
  33.     cout << "L: ";
  34.     for (auto x : L) {
  35.         cout << x << " ";
  36.     }
  37.     cout << endl;
  38.  
  39.     int inf = 1e9;
  40.     for (int i = 0; i < n; ++i) {
  41.         cout << "v " << i << ": ";
  42.         int min_cost = inf;
  43.         int max_cost = 0;
  44.         for (int k = H[i]; k != -1; k = L[k]) {
  45.             int j = J[k];
  46.             int c = C[k];
  47.             min_cost = min(min_cost, c);
  48.             max_cost = max(max_cost, c);
  49.         }
  50.         int del = max_cost - min_cost;
  51.         if (del != -inf) cout << del << endl;
  52.         else cout << "no edjes" << endl;
  53.     }
  54. }
  55. /*
  56. 4 5
  57. 0 1 2 1 0
  58. 1 2 3 3 2
  59. 0 1 2 3 4
  60. */
Advertisement
Add Comment
Please, Sign In to add comment