⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fence.cpp

📁 dd牛的usaco源代码!对学习算法
💻 CPP
字号:
/*
ID: dd.ener1
PROG: fence
LANG: C++
*/
#include <cstdio>
#include <cstring>
using namespace std;

const long N=500;//顶点以1-500编号 
long G[510][510];//记录两个顶点之间边的条数
long con[510];//每个点的度 
long cir[1100];
long cirsize;

inline long& g(long a,long b){
	if(a<b)return G[a][b];
	return G[b][a];
}
void input(){
	memset(G,0,sizeof(G));
	memset(con,0,sizeof(con));
	freopen("fence.in","r",stdin);
	long m;
	scanf("%d",&m);
	while(m--){
		long a,b;
		scanf("%d%d",&a,&b);
		++g(a,b);
		++con[a];
		++con[b];
	}
}
inline void del_edge(long a,long b){
	--g(a,b);
	--con[a];
	--con[b];
}
void find(long k){
	while(con[k])
		for(long i=1;i<=N;++i)
			if(g(k,i)){
				del_edge(k,i);
				find(i);
			}
	cir[cirsize++]=k;
}
void solve(){
	cirsize=0;
	long beg=1;
	for(long i=N;i>=0;--i)
		if(con[i]%2)beg=i;
	find(beg);
}
void output(){
	freopen("fence.out","w",stdout);
	for(--cirsize;cirsize>=0;--cirsize)
		printf("%d\n",cir[cirsize]);
}
int main(){
	input();
	solve();
	output();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -