B题提供一个数据生成器
需要环境:C++17(如果电脑没有C++17环境的话可以复制到牛客里面跑,虽然这样没法对拍了)
#include <bits/stdc++.h> // using std::endl; #define endl "\n" using PII = std::pair<int,int>; std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count()); constexpr int N=10, M=35, Q=10; constexpr int MAXN=20; // 权值范围 int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int n=N, m=M, q=Q; std::cout<<n<<" "<<m<<" "<<q<<"\n"; std::set<PII>st; std::vector<std::tuple<int,int,int>>edges; while(edges.size()<m){ int u=rng()%n+1, v=rng()%n+1; if(u==v || st.find(std::minmax(u,v))!=st.end()) continue; // if(u==v || st.contains(std::minmax(u,v))) continue; st.emplace(std::minmax(u,v)); int w=rng()%MAXN+1; edges.emplace_back(u,v,w); } for(auto &[u,v,w]:edges) std::cout<<u<<" "<<v<<" "<<w<<"\n"; std::vector<std::unordered_set<int>>querys(q); for(auto &i:querys){ int k=rng()%n+1; while(i.size()<k) i.emplace(rng()%n+1); } for(auto &i:querys){ std::cout<<i.size()<<" "; for(auto &j:i) std::cout<<j<<" "; std::cout<<"\n"; } return 0; }