博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #288 (Div. 2)D. Tanya and Password 欧拉通路
阅读量:6721 次
发布时间:2019-06-25

本文共 3153 字,大约阅读时间需要 10 分钟。

D. Tanya and Password

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/508/problem/D

Description

While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password out. Each three-letter substring was written the number of times it occurred in the password. Thus, Tanya ended up with n pieces of paper.
Then Tanya realized that dad will be upset to learn about her game and decided to restore the password or at least any string corresponding to the final set of three-letter strings. You have to help her in this difficult task. We know that dad's password consisted of lowercase and uppercase letters of the Latin alphabet and digits. Uppercase and lowercase letters of the Latin alphabet are considered distinct.

Input

The first line contains integer n (1 ≤ n ≤ 2·105), the number of three-letter substrings Tanya got.
Next n lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit.

Output

If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO".

If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option.

Sample Input

5

aca
aba
aba
cab
bac

Sample Output

YES

abacaba

HINT

 

题意

 

题解:

先hash一下每一个点

然后确定起点和终点,起点就是出度比入度大一的点

终点就是入度比出度大一的位置

然后我们再dfs一发起点就好了

代码:

 

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define test freopen("test.txt","r",stdin) #define maxn 2000001#define mod 10007#define eps 1e-9int Num;char CH[20];const int inf=0x3f3f3f3f;const ll infll = 0x3f3f3f3f3f3f3f3fLL;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}inline void P(int x){ Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts("");}//**************************************************************************************vector
edges[66000];int in[66000],out[66000],cnt[66000];string ans;void dfs(int i){ while(cnt[i]
>s; u=s[0]*256+s[1]; v=s[1]*256+s[2]; edges[u].push_back(v); in[u]++; out[v]++; } start=u; int l=0,r=0; for(i=0;i<66000;++i) { int d=in[i]-out[i]; if(d==1){ l++; start=i; } else if(d==-1) r++; else if(d!=0) { printf("NO\n"); return 0; } if(l>1 || r>1) { printf("NO\n"); return 0; } } dfs(start); ans+=(char)(start/256); reverse(ans.begin(),ans.end()); if(ans.length()!=n+2) printf("NO\n"); else cout<<"YES\n"<
<

 

转载地址:http://djcmo.baihongyu.com/

你可能感兴趣的文章
java中的sortset集合
查看>>
cxgrid导出
查看>>
Exsi服务故障
查看>>
电子商务思维导图精品荟萃:电子商务思维导图大全
查看>>
使用NS2模拟多媒体通讯与无线网络(一)
查看>>
Smart pointers
查看>>
关于rsync中/etc/rsync.password的权限故障:
查看>>
struts.xml配置详解
查看>>
IPSEC ***两个阶段的协商过程
查看>>
稻盛和夫自传读书笔记
查看>>
我的友情链接
查看>>
系统自带sysprep工具重置系统
查看>>
图书推荐:《世界上下五千年大全集》
查看>>
asp.net怎样在URL中使用中文、空格、特殊字符
查看>>
git命令
查看>>
Linux中Yum 出现 Temporary failure in name resolution 解决方案
查看>>
神州数码不同OSPF进程及区域间的通信 实例
查看>>
RHEL AS4下升级oracle10g到10.2.0.3
查看>>
图说:如何给Metro 开始屏幕图标分组
查看>>
HAProxy负载平衡集群
查看>>