我自己做这题时想到的是另外的解法(我是边双缩点加换根dp qwq),并非题解的直接找桥,自己调了一会,最后确实过了。在此留下一个小数据生成器方便对拍。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#include <climits>
#include <assert.h>
#include <array>
#include <ctime>
#include <cstring>
#include <random>
#include <bitset>
#include <chrono>
#define ll long long
#define ff first
#define ss second
#define please return
#define AC 0
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define endl "\n"
#define sendl " \n"
#define space " "
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
void solve() {
int n = rng() % 20;
int m = n + rng() % 10;
m = std::min(n * (n - 1), m);
int k = rng() % n + 1;
int l = rng() % n + 1;
std::cout << n << space << m << space << k << space << l << endl;
std::set<int> se;
for(int i = 1; i <= k; i++){
int now = rng() % n + 1;
while(se.count(now)){
now = rng() % n + 1;
}
se.insert(now);
std::cout << now << sendl[i == k];
}
se.clear();
for(int i = 1; i <= l; i++){
int now = rng() % n + 1;
while(se.count(now)){
now = rng() % n + 1;
}
se.insert(now);
std::cout << now << sendl[i == l];
}
std::set<std::pair<int, int>> se2;
for(int i = 2; i <= n; i++){
int x = rng() % i;
if(x == 0)
x = 1;
se2.insert({x, i});
std::cout << x << space << i << endl;
}
m -= n - 1;
for(int i = 1; i <= m; i++){
int x = rng() % n + 1;
int y = rng() % x;
if(y == 0)
y = 1;
while(se2.count({y, x}) || x == 1){
x = rng() % n + 1;
if(x == 1)
continue;
y = rng() % x;
if(y == 0)
y = 1;
}
se2.insert({y, x});
std::cout << y << space << x << endl;
}
}
int main() {
int t = 1;
//scanf("%d",&t);
while(t--) solve();
return 0;
}