uva 10054 The Necklace 欧拉回路ha
来源:互联网 发布:美工和ui设计师的区别 编辑:程序博客网 时间:2024/06/07 06:44
题意:给你n个珠子,一个珠子分为两半有两种颜色,用1到50来表示50种不同的颜色。把这些珠子串起来,两个紧挨着的珠子要满足一个条件就是接触的那部分颜色要相同
例如(1,2)(2,4),两个珠子的接触部分颜色相同都为2。当然,因为珠子最后是连成环的,第一个珠子和最后一个珠子也会接触,也要买满足这个条件
先输入T,有T组数据
输入n,有n个珠子
下面n行每行两个数字表示这个珠子的两个颜色,然后问你能不能连成一条链,能的话输出任意一种连接情况即可,不能的话输出失败
2017年08月09日11:10:09
收获:差点以为敲不下去了。。只能去leaderboard去看了看别人的怎么用链式前向星做这题的。
然后看到了自己逗比的地方
struct Node{ int u,v;}node[mxn<<1];int vis[mxn];int head[mxn],tot;int du[mxn];struct Edge{ int v,nxt;}edge[mxn<<1];int vise[mxn<<1];void add(int u,int v){ edge[tot].v=v;edge[tot].nxt=head[u];head[u]=tot++;}void euler(int u){ du[u]--; for(int i=head[u];~i;i=edge[i].nxt){ int v=edge[i].v; if(!vise[i]){ vise[i]=1; vise[i^1]=1; euler(v); pf("%d %d\n",v,u); } }}int main(){ int T;sf("%d",&T); int cas=0; while(T--){ if(cas)puts(""); pf("Case #%d\n",++cas); mem(vise,0); mem(head,-1);tot=0;mem(du,0); int n;sf("%d",&n); rep(i,1,n){ int u,v;sf("%d%d",&u,&v);add(u,v);add(v,u); du[u]++;du[v]++; } int flag=0; for(int i=1;i<=50;++i)if(du[i]&1){puts("some beads may be lost");flag=1;break;} if(!flag)for(int i=1;i<=50;++i)if(du[i]>0)euler(i); }}
0 0
- uva 10054 The Necklace 欧拉回路ha
- UVa 10054 - The Necklace(欧拉回路)
- UVA 10054 the necklace 欧拉回路
- UVA 10054 - The Necklace 欧拉回路
- UVa 10054 - The Necklace 欧拉回路
- uva 10054 The Necklace (欧拉回路)
- UVa 10054 The Necklace(欧拉回路)
- UVA 10054 The Necklace 欧拉回路
- The Necklace - UVa 10054 欧拉回路
- UVA 10054 - The Necklace(欧拉回路)
- uva 10054 The Necklace 欧拉回路
- uva 10054 The Necklace 欧拉回路
- UVA 10054 The Necklace(欧拉回路)
- UVA - 10054 The Necklace 欧拉回路
- UVa 10054 - The Necklace, 欧拉回路+打印路径
- uva 10054 The Necklace(欧拉回路)
- Uva - 10054 - The Necklace(欧拉回路)
- UVA 10054 The Necklace(欧拉回路+输出路径)
- os.path
- jzoj P1135 【2011.12.10普及模拟】泽泽在中国
- MongoDB 的基本操作
- React 关于array.map应该注意的问题
- Osenbei Aizu
- uva 10054 The Necklace 欧拉回路ha
- spring,hiberante之*** is not valid without active transaction
- Android问题:Your project Path contains non-ASCll characters
- [LeetCode]133. Clone Graph
- 关于ASP.NET Web Api的HelpPage文档注释问题
- Java web给Android写接口时用SQL Sever2014所遇到的大坑
- 项目设计思想学习
- 341. Flatten Nested List Iterator
- 第四届蓝桥杯【省赛试题1】高斯日记