POJ
来源:互联网 发布:如何保证数据的准确性 编辑:程序博客网 时间:2024/06/08 10:47
题解:直接欧拉回路套模板即可
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;const int mx = 5e4+5;struct node{ int u,v; int next; bool operator<(const node &a)const{ if(u!=a.u) u < a.u; return v < a.v; }}a[mx],E[mx<<1];int head[mx],vis[mx<<1],tot;void init(){ tot = 0; memset(vis,0,sizeof(vis)); memset(head,0,sizeof(head));}void add(int u,int v){ tot++; E[tot].u = u; E[tot].v = v; E[tot].next = head[u]; head[u] = tot;}void dfs(int u){ for(int i = head[u]; i; i = E[i].next){ int v = E[i].v; if(!vis[i]){ vis[i] = 1; dfs(v); } } printf("%d\n",u);}int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ init(); for(int i = 0; i < m; i++){ int u,v; scanf("%d%d",&u,&v); add(u,v); add(v,u); } dfs(1); } return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- hdu 1285 确定比赛名次 (拓扑排序)
- 库time.h初探
- Linux设置CRT/mysql SSH登陆超时
- 32位操作系统与64位操作系统的区别
- ubuntu 命令行模式连接wifi
- POJ
- matlab做数据拟合
- Android Gradle打包
- Struts2中action注解使用异常
- HDU 2199 Can you solve this equation? 牛顿迭代法 || 二分
- hadoop的安装
- 合并区间-LintCode
- 矩阵的乘积【水题】
- 通过字节流复制粘贴文档