Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int ms = 5e5+5;
- int arr[ms];
- vector<pair<int, int>> edges;
- main() {
- int n;
- cin >> n;
- for(int i = 0; i < n; i++) {
- int u, v;
- cin >> u >> v;
- if(v != n) {
- cout << "NO\n";
- return 0;
- }
- arr[u]++;
- }
- sort(arr, arr+n);
- queue<int> q;
- for(int i = 1; i < n; i++) {
- if(arr[i] == 0) q.push(i);
- else {
- int cur = n;
- for(int j = 1; j < arr[i]; j++) {
- if(q.empty()) {
- cout << "NO\n";
- return 0;
- }
- int u = q.front();
- q.pop();
- edges.emplace_back(cur, u);
- }
- edges.emplace_back(cur, i);
- }
- }
- cout << "YES\n";
- for(auto e : edges) {
- cout << e.first << ' ' << e.second << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement