/*欧拉回路*/
/*这到题UVA 虽然AC但是因为 给的数据有点弱,其实还有种情况:需要判断一下图是否是一个连通图,比如说如果最好串成了2条项链,而不能穿成一条,就应该输出不存在*/
//判断联通可以在最后输出前扫一下,很简单我就不写了
#include <stdio.h>
#include <string.h>
int map[200][200], vis[200][200];
int num[100];
typedef struct
{int u, v;
}p;
p stack[1000];
int top, n;
void push( int u, int v )
{stack[top].u = u;stack[top].v = v;top++;
}
p pop()
{return stack[--top];
}
void euler( int u )
{int v;for( v = 1; v <= 60; v++ )if( map[u][v] ){map[u][v]--;map[v][u]--;euler(v);push(u, v);}
}
int empty()
{if( top == 0 )return 1;return 0;
}
int main()
{freopen( "in", "r", stdin );p ps;int T, i, j, cout = 0, u, v,flag, t;scanf( "%d", &T );while( T-- ){t = 0;flag = 0;memset( num, 0, sizeof(num) );memset(stack, 0, sizeof(stack) );memset(map, 0, sizeof(map) );memset(vis, 0, sizeof(vis) );scanf( "%d", &n );for( i = 1; i <= n; i++ ){scanf( "%d%d", &u, &v );if( u != v )t = 1;map[u][v]++;map[v][u]++;num[u]++;num[v]++;}if( !t ){printf( "Case #%d\n", ++cout );while( n-- )printf( "%d %d\n", u, v );printf( "\n" );continue;}for( i = 1; i <= 60; i++ )if( num[i] % 2 )flag = 1;if( flag ){printf( "Case #%d\n", ++cout );printf( "some beads may be lost\n\n" );}else{for( i = 1; i <= 60; i++ )if( num[i] > 0 ){euler( i );break;} printf( "Case #%d\n", ++cout );while( !empty() ){ps = pop();printf( "%d %d\n", ps.u, ps.v );}printf( "\n" );}}return 0;
}
详细解决方案
UVA 10054
热度:24 发布时间:2024-01-11 16:41:06.0
相关解决方案
- 联网有时会报java.io.IOException: error 10054 during TCP read异常
- 上传大文件过程中,遇到异常代码 10054: 连接被服务器重置
- git pull报错:error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
- 【GIT】clone时出现RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errfno 10054
- Window生成SSH并使其生效:解决git提交报错OpenSSL SSL_read: Connection was reset, errno 10054
- uva 10054 The Necklace
- vgg16 ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
- 关于git提交github出现errno 10054、port 443: Timed out等问题解决
- Run-time error '10054':The connection is reset by remote side的处理
- UVA 10054