Raslboyy

1932v1

Nov 27th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. #include <algorithm>
  5. #include <string>
  6. #include <math.h>
  7. #include <climits>
  8.  
  9. //#include <chrono>
  10. //#include <fstream>
  11. //#include <bits/stdc++.h>
  12.  
  13. #define mp make_pair
  14. #define pb push_back
  15. #define eb emplace_back
  16. #define x first
  17. #define y second
  18. #define sz(x) (int)x.size()
  19. #define all(x) begin(x), end(x)
  20. #define rall(x) rbegin(x), rend(x)
  21. #define FOR(i,a,b) for (int i = (a); i < (b); i++)
  22. #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
  23.  
  24. using namespace std;
  25.  
  26. typedef unsigned long long ull;
  27. typedef long long ll;
  28. typedef long double ld;
  29. typedef pair<int, int> pi;
  30. typedef pair<ll, ll> pl;
  31. typedef vector<int> veci;
  32. typedef vector<bool> vecb;
  33. typedef vector<vector<int>> vvi;
  34. typedef vector<vector<bool>> vvb;
  35.  
  36. const int INF_I = 1e9;
  37. const ll INF_LL = 1e18;
  38.  
  39. int m, k, n;
  40. vvb foe;
  41. vecb used;
  42. veci green, yellow, p;
  43.  
  44. bool dfs(int v) {
  45.     if (used[v])
  46.         return false;
  47.     used[v] = true;
  48.     for (int i : yellow)
  49.         if (!foe[v][i] && (p[i] == -1 || dfs(p[i]))) {
  50.             p[i] = v;
  51.             return true;
  52.         }
  53.     return false;
  54. }
  55.  
  56. int main() {
  57.     /*ifstream cin("in.txt");
  58.     ofstream cout("out.txt");
  59.     auto start_time = chrono::high_resolution_clock::now();*/
  60.  
  61.     ios::sync_with_stdio(false);
  62.     cin.tie(0);
  63.     cout.tie(0);
  64.  
  65.     int t, q;
  66.     cin >> m >> k >> n >> t;
  67.     green.assign(m, 0);
  68.     yellow.assign(k, 0);
  69.     for (int i = 0; i < m; i++) green[i] = i;
  70.     for (int i = 0; i < k; i++) yellow[i] = i;
  71.     foe.assign(m, vecb(k));
  72.     p.assign(k, -1);
  73.     for (int i = 0; i < t; i++) {
  74.         int a, b;
  75.         cin >> a >> b;
  76.         a--; b -= (m + 1);
  77.         foe[a][b] = 1;
  78.     }
  79.     cin >> q;
  80.     int cnt_g = 0, cnt_y = 0;
  81.     for (int i = 0; i < q; i++) {
  82.         int a; cin >> a;
  83.         a--;
  84.         if (a < m) {
  85.             swap(green[cnt_g], green[a]);
  86.             cnt_g++;
  87.         }
  88.         else {
  89.             a -= m;
  90.             swap(yellow[cnt_y], yellow[a]);
  91.             cnt_y++;
  92.         }
  93.     }
  94.     int cnt_n = 0;
  95.     for (int i = 0; i < m && cnt_n < n; i++) {
  96.         used.assign(m, 0);
  97.         int a = (int)dfs(green[i]);
  98.         cnt_n += a;
  99.     }
  100.  
  101.     if (cnt_n < n) {
  102.         cout << "NO\n";
  103.         return 0;
  104.     }
  105.    
  106.     for (int i = 0; i < cnt_y; i++)
  107.         if (p[yellow[i]] == -1) {
  108.             cout << "NO\n";
  109.             return 0;
  110.         }
  111.     int cnt = 0;
  112.     for (int i = 0; i < k; i++)
  113.         if (p[i] != -1 && lower_bound(green.begin(), green.begin() + cnt_g, p[i]) != green.begin() + cnt_g)
  114.             cnt++;
  115.     if (cnt != cnt_g) {
  116.         cout << "NO\n";
  117.         return 0;
  118.     }
  119.  
  120.     cout << "YES\n";
  121.     for (int i = 0; i < k; i++)
  122.         if (p[i] != -1)
  123.             cout << p[i] + 1 << " " << m + i + 1 << "\n";
  124.    
  125.    
  126.     /*auto end_time = chrono::high_resolution_clock::now();
  127.     chrono::duration<double> duration = end_time - start_time;
  128.     cout << duration.count() << "\n";
  129.     cin.close();
  130.     cout.close();*/
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment