hdu1116 欧拉回路
//Accepted 248 KB 125 ms
//欧拉回路
//以26个字母为定点,一个单词为从首字母到末尾字母的一条边
//下面就是有向图判断欧拉回路
//连通+节点入度和==出度和 或者 存在一对节点一个入度比出度大1,一个小1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
;
int a[imax_n][imax_n];
bool used[imax_n];
bool vis[imax_n];
int cnt_in[imax_n],cnt_out[imax_n];
int n;
];
queue<int >q;
void bfs(int s)
{
while (!q.empty()) q.pop();
//if (used[s]==0) return 0;
q.push(s);
vis[s]=;
while (!q.empty())
{
int x=q.front();
q.pop();
;i<imax_n;i++)
{
&& !vis[i] && a[x][i])
{
vis[i]=;
q.push(i);
}
}
}
}
bool judge()
{
int flag;
;i<=;i++)
{
memset(vis,,sizeof(vis));
bfs(i);
flag=;
;j<=;j++)
&& !vis[j]) flag=;
) ;
}
;
}
bool slove()
{
int p,ne;
p=ne=;
;i<=;i++)
{
int t=cnt_in[i]-cnt_out[i];
) continue;
)
{
p++;
) ;
continue;
}
)
{
ne++;
) ;
continue;
}
;
}
&& ne== || p== && ne==)) ;
;
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
int x,y;
memset(a,,sizeof(a));
memset(used,,sizeof(used));
memset(cnt_in,,sizeof(cnt_in));
memset(cnt_out,,sizeof(cnt_out));
;i<n;i++)
{
scanf("%s",s);
int l=strlen(s);
x=s[]-;
y=s[l-]-;
used[s[]-]=true;
used[s[l-]-]=true;
a[x][y]=;
cnt_out[x]++;
cnt_in[y]++;
}
&& slove()==)
printf("Ordering is possible.\n");
else
printf("The door cannot be opened.\n");
}
;
}
hdu1116 欧拉回路的更多相关文章
- hdu-1116(欧拉回路+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1116 思路:将字符串的头元素和尾元素视为图的x,y节点,然后合并x,y. 如果这个图不连通,则门不能打 ...
- ACM/ICPC 之 混合图的欧拉回路判定-网络流(POJ1637)
//网络流判定混合图欧拉回路 //通过网络流使得各点的出入度相同则possible,否则impossible //残留网络的权值为可改变方向的次数,即n个双向边则有n次 //Time:157Ms Me ...
- [poj2337]求字典序最小欧拉回路
注意:找出一条欧拉回路,与判定这个图能不能一笔联通...是不同的概念 c++奇怪的编译规则...生不如死啊... string怎么用啊...cincout来救? 可以直接.length()我也是长见识 ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
- UVA 10054 the necklace 欧拉回路
有n个珠子,每颗珠子有左右两边两种颜色,颜色有1~50种,问你能不能把这些珠子按照相接的地方颜色相同串成一个环. 可以认为有50个点,用n条边它们相连,问你能不能找出包含所有边的欧拉回路 首先判断是否 ...
- POJ 1637 混合图的欧拉回路判定
题意:一张混合图,判断是否存在欧拉回路. 分析参考: 混合图(既有有向边又有无向边的图)中欧拉环.欧拉路径的判定需要借助网络流! (1)欧拉环的判定:一开始当然是判断原图的基图是否连通,若不连通则一定 ...
- codeforces 723E (欧拉回路)
Problem One-Way Reform 题目大意 给一张n个点,m条边的无向图,要求给每条边定一个方向,使得最多的点入度等于出度,要求输出方案. 解题分析 最多点的数量就是入度为偶数的点. 将入 ...
- UVa 12118 检查员的难题(dfs+欧拉回路)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10054 (欧拉回路) The Necklace
题目:这里 题意:有一种由彩色珠子连接而成的项链,每个珠子两半由不同颜色(由1到50的数字表示颜色)组成,相邻的两个珠子在接触的地方颜色相同,现在有一些零碎的珠子,确认它是否能 复原成完整的项链. 把 ...
随机推荐
- dede如何新建一个ajax服务端输出文件
<?phprequire_once(dirname(__FILE__)."/include/common.inc.php");AjaxHead(); $dsql-> ...
- 设置DIV最小高度以及高度自适应随着内容的变化而变化
<!--退租账单--> <div id="bilsli" onmouseover="showBill(this)"> #bilsli{ ...
- ASP.NET页面与IIS底层交互和工作原理详解
转载自:http://www.cnblogs.com/lidabo/archive/2012/03/13/2393200.html 第一回: 引言 我查阅过不少Asp.Net的书籍,发现大多数作者都是 ...
- CSS3:不可思议的border属性&Web字体图标Font Awesome
CSS3:不可思议的border属性 转载至——译文:不可思议的CSS border属性 原文:Magic of CSS border property Web字体图标Font Awesome 转载 ...
- hdu----(1528)Card Game Cheater(最大匹配/贪心)
Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Roman to Integer [LeetCode]
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- cycleInterpolator 循环加速器
CycleInterpolator Repeats the animation for a specified number of cycles. The rate of change follows ...
- struts2视频学习笔记 21(输入校验的流程)
课时21 输入校验的流程 1.类型转换器对请求参数执行类型转换,并把转换后的值赋给action中的属性. 2.如果在执行类型转换的过程中出现异常,系统会将异常信息保存到ActionContext,co ...
- PHP+mysql常用类库
<?php /** * @title: Ekcms mysql类库 * @version: 1.0 * @author: perry <perry@1kyou.com> * @pub ...
- Android为ViewPager增加切换动画——使用属性动画.
ViewPager作为Android最常用的的组件之一,相信大家在项目中会频繁的使用到的,例如利用ViewPager制作引导页.轮播图,甚至做整个app的表现层的框架等等. Android3.0以下不 ...