LRJ-Example-06-16-Uva10129
#include <cstdio>
#include <cstring>
#include <vector> using namespace std; const int maxn = + ; // at most 1000 lowercase characters // union find set, each set is a tree
// only letters 'a' through 'z' will appear, so totally 26 nodes
const int maxc = ; int parent[maxc]; // parent of each node // find the root node of the set of node x
int findSet(int x) {
return parent[x] == x ? x : findSet(parent[x]);
} int used[maxc];
int degree[maxc]; // degree = out degree - in degree int main() {
int T;
int N; // 1 <= N <= 100000
char word[maxn]; scanf("%d", &T);
while(T--) {
scanf("%d", &N); memset(used, , sizeof(used));
memset(degree, , sizeof(degree)); // init the sets
for(int i = ; i < maxc; i++) parent[i] = i;
int numSet = maxc; for(int i = ; i < N; i++) { // read each word
scanf("%s", word);
int first = word[] - 'a';
int last = word[strlen(word) - ] - 'a';
// there is an edge first --> last
degree[first]++;// out degree
degree[last]--;// in degree used[first] = used[last] = ; int setFirst = findSet(first);
int setLast = findSet(last); if(setFirst != setLast) {
// union
parent[setFirst] = setLast;
numSet--;
}
} vector<int> d;
for(int i = ; i < maxc; i++) {
if(!used[i])
numSet--;
else if (degree[i] != )
d.push_back(degree[i]);
} bool ok = false;
if(numSet == && // all nodes are connected
// Euler circuit, all nodes have degree 0
(d.empty() ||
// Euler path, if d[0] == 1, then d[1] == -1, and vice versa
(d.size() == && (d[] == || d[] == -))))
ok = true; if(ok) printf("Ordering is possible.\n");
else printf("The door cannot be opened.\n");
} return ;
}
LRJ-Example-06-16-Uva10129的更多相关文章
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- 2016/06/16 phpexcel
程序部分 require_once './phpexcel/PHPExcel.php'; // 首先创建一个新的对象 PHPExcel object $objPHPExcel = new ...
- 【NLP新闻-2013.06.16】Representative Reviewing
英语原文地址:http://nlp.hivefire.com/articles/share/40221/ 注:本人翻译NLP新闻只为学习专业英语和扩展视野,如果翻译的不好,请谅解! (实在是读不大懂, ...
- [每日一题2020.06.16] leetcode双周赛T3 5423 找两个和为目标值且不重叠的子数组 DP, 前缀和
题目链接 给你一个整数数组 arr 和一个整数值 target . 请你在 arr 中找 两个互不重叠的子数组 且它们的和都等于 target .可能会有多种方案,请你返回满足要求的两个子数组长度和的 ...
- H3C汇聚层交换机认证在线人数展示系统之CheckList和燃尽图(16/04/06-16/04/13)
一.CheckList(核查表) 序号 事件 计划完成时间 实际完成时间 未延迟 未完成 完成 1 登录口令加密以及解密 16/04/06 16/04/06 Y 2 表的创建和IP以及口令 ...
- JavaSE学习总结第06天_Java语言基础2 & 面向对象1
06.01 二维数组概述和格式1的讲解 二维数组概述:二维数组其实就是一个元素为一维数组的数组 格式1:数据类型[][] 变量名 = new 数据类型[m][n]; m表示这个二维数组有多少个一维 ...
- hadoop 2.7.3本地环境运行官方wordcount
hadoop 2.7.3本地环境运行官方wordcount 基本环境: 系统:win7 虚机环境:virtualBox 虚机:centos 7 hadoop版本:2.7.3 本次先以独立模式(本地模式 ...
- WebAPi之SelfHost自创建证书启动Https疑难解惑及无法正确返回结果
前言 话说又来需求了,之前对于在SelfHost中需要嵌套页面并操作为非正常需求,这回来正常需求了,客户端现在加了https,老大过来说WebAPi访问不了了,这是什么情况,我去试了试,还真是这个情况 ...
- SQL Server-聚焦IN VS EXISTS VS JOIN性能分析(十九)
前言 本节我们开始讲讲这一系列性能比较的终极篇IN VS EXISTS VS JOIN的性能分析,前面系列有人一直在说场景不够,这里我们结合查询索引列.非索引列.查询小表.查询大表来综合分析,简短的内 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试
系列目录 我想测试EF在一百万条数据下的显示时间!这分数据应该有很多同学想要,看看EF的性能! 服务器 现在来向SQL2008R2插入1000000条数据吧 declare @i int; ; beg ...
随机推荐
- IO 性能 $ iostat -kx 2$ vmstat 2 10$ mpstat 2 10$ dstat --top-io --top-bio
这些命令对于调试后端性能非常有用. 检查磁盘使用量:服务器硬盘是否已满? 是否开启了swap交换模式 (si/so)? CPU被谁占用:系统进程? 用户进程? 虚拟机? dstat 是我的最爱.用 ...
- Git pull 强制覆盖本地文件 - CSDN博客
Git pull 强制覆盖本地文件 原创 2015年11月16日 22:07:56 标签: git git fetch --all git reset --hard origin/master git ...
- 关于layui部分表单不显示的问题(Select, checkBox)
原因: 没有使用JS进行初始化 官方说明: https://www.layui.com/doc/base/faq.html layui.use('form', function(){ var form ...
- 杨柳絮-Info:阜阳市多举措治理杨柳絮问题
ylbtech-杨柳絮-Info:阜阳市多举措治理杨柳絮问题 1.返回顶部 1. 阜阳市多举措治理杨柳絮问题 2019-4-15 10:34| 发布者: 戴斐 | 查看: 56407| 评论: 0|原 ...
- 杨柳絮-Info:菏泽多措并举治理杨柳絮 5年内实现“有絮不成灾”
ylbtech-杨柳絮-Info:菏泽多措并举治理杨柳絮 5年内实现“有絮不成灾” 1.返回顶部 1. 菏泽多措并举治理杨柳絮 5年内实现“有絮不成灾” 2019年04月09日 11:44 来源:大 ...
- ecshop二次开发之后台秒杀
1.进入admin->includes->inc_menu.PHP中此文件为定义左侧功能模块超链接 2.添加include/inc_menu.php秒杀管理超链接找链接 $modules[ ...
- 媒体查询(media):设置PC端网页居中显示
@media screen and (min-width: 768px){ body{ background-color: #EAEAEA; } #fater{ width: 640px; margi ...
- 【JZOJ3636】【BOI2012】Mobile(mobile)
Mission 著名的手机网络运营商Totalphone 修建了若干基站收发台,以用于把信号网络覆盖一条新建的高速公路.因为Totalphone 的程序员总是很马虎的,所以,基站的传功功率不能独立设置 ...
- JavaScript字符串、数组、对象方法总结
字符串方法 示例字符串: const str = "hello,kitty,hello,vue "; 一.基本方法 charAt(n) 返回指定索引的字符 charCodeAt(n ...
- Python科学计算生态圈