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的数字表示颜色)组成,相邻的两个珠子在接触的地方颜色相同,现在有一些零碎的珠子,确认它是否能 复原成完整的项链. 把 ...
随机推荐
- js用ajax和jison在不同页面的php和html之间互相传值的方法
<script> ;//这个id必须有,如果是空值,无法实现交互.有点郁闷.... var json; $.ajax({ url:"../member/wenzhanglishi ...
- JQUERY学习(壹)
一.jQuery的引言 1.jQuery框架:对JavaScript的封装,简化js开发 2.jQuery框架的好处: 1)语法简单 js中:document.getElementById(" ...
- C# 给软件加注册码功能
为自己写的程序加一个注册功能吧.生成的机器号是根据CPU和硬盘号来的,根据自己的需求改成是否是随机生成. 代码直接粘贴到新建类覆盖原代码就能直接用了. using System; using Syst ...
- jquery学习笔记1
(1) jQuery的Id选择器: $("#btnShow") (2) 事件绑定函数 bind() $("#btnAdd").bind("click& ...
- P92认识对话框
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- sh脚本异常:bad interpreter: No such file or directory
转:http://bluedest.iteye.com/blog/1674963 在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file o ...
- hdu----(2084)数塔(dp)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- Maximal Rectangle [LeetCode]
Problem Description: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle co ...
- IDEA配置maven
步骤:Setting....或Ctrl+Alt+S
- JS比较好用的一些方法搜集
JS比较好用的一些方法搜集 Math.ceil(x) -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入 Math.floor(x)--返回小于等于数字参数的最大整数,对数字进行下舍入 ...