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

📄 pku2230.cpp

📁 这是ACM 方面的资料 是PKU的 北京大学的出来的
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
#define size 120000
typedef struct Node
{
	int x, nxt;
}Node;

Node nd[size];
int M, N;
int end;

void Insert(int a, int b)
{
	int p;
	
	nd[end].x = b;
	nd[end].nxt = 0;
	p = a;
	while (nd[p].nxt)
	{
		p = nd[p].nxt;
	}
	nd[p].nxt = end;
	end++;

	nd[end].x = a;
	nd[end].nxt = 0;
	p = b;
	while (nd[p].nxt)
	{
		p = nd[p].nxt;
	}
	nd[p].nxt = end;
	end++;
}

void DFS(int x)
{
	int p;
	do
	{
		p = nd[x].nxt;
		if (p == 0)
		{
			break;
		}
		nd[x].nxt = nd[p].nxt;
		DFS(nd[p].x);
	}while (p);
	printf("%d\n", x);
}

int main()
{
	int i, s, e;
	while (scanf("%d %d", &N, &M) != -1)
	{
		memset(nd, 0, sizeof(nd));
		end = N + 10;
		for (i = 0; i < M; i++)
		{
			scanf("%d %d", &s, &e);
			Insert(s, e);
		}
		DFS(1);
	}
	return 0;
}

⌨️ 快捷键说明

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