《特殊数据生成》
在折腾了一天的cyaron还是无法正常运行,我觉得自己来写一份c++的数据生成总和。
1:有向无环图。(可能有重边)
bool vis[N]; map<pii,int> mp; void DAG(int maxn,int maxm) { freopen("data3.in","w",stdout); srand(time(NULL)); int n = rand() % maxn + 1; int m = min(maxm,n * n / 20); printf("%d %d\n",n,m); int now = 1; while(1) { vis[now] = 1; int num = rand() % (n - 1) + 1; if(n * (n - now) < m / 2) num = n - now; for(int i = 1;i <= num && m > 0;++i) { int x = rand() % (n - now) + now + 1; printf("%d %d\n",now,x); mp[pii(now,x)] = 1; m--; } if(m == 0) break; now = rand() % n + 1; while(vis[now]) now = rand() % n + 1; } }
2:树
vector<int> vec1,vec2; void Tree() { srand(time(NULL)); int n = rand() % N + 1; printf("%d\n",n); for(int i = 1;i <= n;++i) vec2.push_back(i); vec1.push_back(1); vec1.push_back(2); vec2.erase(vec2.begin()); vec2.erase(vec2.begin()); printf("1 2\n"); for(int i = 2;i < n;++i) { int x = rand() % vec1.size(); int y = rand() % vec2.size(); printf("%d %d\n",vec1[x],vec2[y]); vec1.push_back(vec2[y]); vec2.erase(vec2.begin() + y); } for(int i = 1; i <= n;++i) { int x = rand() % N + 1; printf("%d\n",x); } }