首页 > 代码库 > 数据生成程序
数据生成程序
//数据生成程序/*#include <iostream>#include <cstdio>#include <map>#include <algorithm>#include <vector>#include <cstdlib>#include <ctime>#include <set>using namespace std;int main() { int t = 999; srand( time(NULL) ); freopen("e.txt","w",stdout); printf("%d\n",t); while(t--) { int n = rand() % 2000 + 1; int m = rand() % 1000 + 1; printf("%d %d\n", n, m); for(int i = 0; i < m; i++) { int x = rand() % n + 1; int y = rand() % n + 1; printf("%d %d\n",x, y); } }}*///标程#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 2005;int fa[maxn], r[maxn];void init(int n){ for(int i = 0; i <= n; i++) { fa[i] = i; r[i] = 0; }}int find(int x){ if(fa[x] == x) return x; int fx = fa[x]; fa[x] = find(fa[x]); r[x] = ( r[fx] + r[x] ) % 2; return fa[x];}void unin(int x, int y){ int fx = find(x); int fy = find(y); if(fx != fy) { fa[fy] = fx; r[fy] = ( r[x] + r[y] + 1 ) % 2; }}int main(){ int t; int n, m; int a, b; freopen("e.txt","r",stdin); freopen("f.txt","w",stdout); scanf("%d",&t); for(int kase = 1; kase <= t; kase++) { bool flag = true; scanf("%d %d",&n, &m); init(n); for(int i = 0; i < m; i++){ scanf("%d %d",&a, &b); if(!flag) continue; if(find(a) != find(b)) { unin(a, b); } else { if(find(a) == find(b) && r[a] == r[b]){ flag = false; } } } printf("Scenario #%d:\n", kase); if(flag) { puts("No suspicious bugs found!"); } else { puts("Suspicious bugs found!"); } if(kase != t) puts(""); }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。