Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <list>
- #include <algorithm>
- #include <string>
- #include <math.h>
- #include <climits>
- //#include <chrono>
- //#include <fstream>
- //#include <bits/stdc++.h>
- #define mp make_pair
- #define pb push_back
- #define eb emplace_back
- #define x first
- #define y second
- #define sz(x) (int)x.size()
- #define all(x) begin(x), end(x)
- #define rall(x) rbegin(x), rend(x)
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pi;
- typedef pair<ll, ll> pl;
- typedef vector<int> veci;
- typedef vector<bool> vecb;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<bool>> vvb;
- const int INF_I = 1e9;
- const ll INF_LL = 1e18;
- int m, k, n;
- vvb foe;
- vecb used;
- veci green, yellow, p;
- bool dfs(int v) {
- if (used[v])
- return false;
- used[v] = true;
- for (int i : yellow)
- if (!foe[v][i] && (p[i] == -1 || dfs(p[i]))) {
- p[i] = v;
- return true;
- }
- return false;
- }
- int main() {
- /*ifstream cin("in.txt");
- ofstream cout("out.txt");
- auto start_time = chrono::high_resolution_clock::now();*/
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int t, q;
- cin >> m >> k >> n >> t;
- green.assign(m, 0);
- yellow.assign(k, 0);
- for (int i = 0; i < m; i++) green[i] = i;
- for (int i = 0; i < k; i++) yellow[i] = i;
- foe.assign(m, vecb(k));
- p.assign(k, -1);
- for (int i = 0; i < t; i++) {
- int a, b;
- cin >> a >> b;
- a--; b -= (m + 1);
- foe[a][b] = 1;
- }
- cin >> q;
- int cnt_g = 0, cnt_y = 0;
- for (int i = 0; i < q; i++) {
- int a; cin >> a;
- a--;
- if (a < m) {
- swap(green[cnt_g], green[a]);
- cnt_g++;
- }
- else {
- a -= m;
- swap(yellow[cnt_y], yellow[a]);
- cnt_y++;
- }
- }
- int cnt_n = 0;
- for (int i = 0; i < m && cnt_n < n; i++) {
- used.assign(m, 0);
- int a = (int)dfs(green[i]);
- cnt_n += a;
- }
- if (cnt_n < n) {
- cout << "NO\n";
- return 0;
- }
- for (int i = 0; i < cnt_y; i++)
- if (p[yellow[i]] == -1) {
- cout << "NO\n";
- return 0;
- }
- int cnt = 0;
- for (int i = 0; i < k; i++)
- if (p[i] != -1 && lower_bound(green.begin(), green.begin() + cnt_g, p[i]) != green.begin() + cnt_g)
- cnt++;
- if (cnt != cnt_g) {
- cout << "NO\n";
- return 0;
- }
- cout << "YES\n";
- for (int i = 0; i < k; i++)
- if (p[i] != -1)
- cout << p[i] + 1 << " " << m + i + 1 << "\n";
- /*auto end_time = chrono::high_resolution_clock::now();
- chrono::duration<double> duration = end_time - start_time;
- cout << duration.count() << "\n";
- cin.close();
- cout.close();*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment