跳到正文

个人记录

仙人掌生成,能用就行

zzzyyyyhhhhh约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年1月8日
收录
2025年12月12日
更新
2026年11月8日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
bool v[1000];
vector<int> a[1000];
vector<pair<int,int> > e;
vector<int> tmp;
int n,now;
mt19937 rd(__builtin_ia32_rdtsc());
inline bool dfs(int x,int fa)
{
	if(v[x])return 0;
	if(x!=now&&rd()%n==0)
	{
		e.push_back({min(x,now),max(x,now)});
		return 1;
	}
	for(auto i:a[x])
	{
		if(i==fa)continue;
		if(dfs(i,x)){v[x]=1;return 1;}
	}
	return 0;
}
signed main()
{
	freopen("in.in","w",stdout);
	n=rd()%7+1;
	// cout<<n<<' '<<n-1<<" 1\n";
	int x,y;
	for(int i=2;i<=n;i++)
	{
		x=i,y=rd()%(i-1)+1;
		a[y].push_back(x);
		a[x].push_back(y);
		e.push_back({min(x,y),max(x,y)});
	}
	int t=rd()%n+1;
	for(int i=1;i<=t;i++)
	{
		now=rd()%n+1;
		if(v[now])continue;
		tmp.clear();
		dfs(now,now);
	}
	sort(e.begin(),e.end());
	e.erase(unique(e.begin(),e.end()),e.end());
	cout<<n<<' '<<e.size()<<" 10\n";
	for(auto i:e)cout<<i.first<<' '<<i.second<<' '<<rd()%5+1<<'\n';
	for(int i=1;i<=10;i++)cout<<rd()%n+1<<' '<<rd()%n+1<<'\n';
}
原文