General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
84119045 Practice:
JKLover
508D - 22 GNU C++17 Accepted 77 ms 12852 KB 2020-06-18 04:49:08 2020-06-18 04:49:08
 
 
→ Source
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
void print(int x)
{
	if (x >= 10)
		print(x / 10);
	putchar('0' + x % 10);
}
void write(int x, char c)
{
	if (x < 0)
		putchar('-'), x = -x;
	print(x);
	putchar(c);
}
const int Base = 26 * 2 + 10, N = 2e5 + 10;
int trans(char c)
{
	if ('A' <= c && c <= 'Z')
		return c - 'A';
	if ('a' <= c && c <= 'z')
		return c - 'a' + 26;
	return c - '0' + 52;
}
vector<pair<int, int> > G[Base * Base];
int n, indeg[Base * Base], outdeg[Base * Base], p[N], t = 0;
char buf[N][10];
void dfs(int x, int id)
{
	while (!G[x].empty())
	{
		auto tmp = G[x].back();
		G[x].pop_back();
		dfs(tmp.first, tmp.second);
	}
	if (id != -1)
		p[++t] = id;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; ++i)
	{
		scanf("%s", buf[i]);
		int u = trans(buf[i][0]) * Base + trans(buf[i][1]);
		int v = trans(buf[i][1]) * Base + trans(buf[i][2]);
		++indeg[v], ++outdeg[u];
		G[u].push_back(make_pair(v, i));
	}
	int f = 1, st = -1, ed = -1;
	for (int i = 0; i < Base * Base && f; ++i)
	{
		if (indeg[i] == outdeg[i])
			continue;
		if (indeg[i] + 1 == outdeg[i])
		{
			if (st == -1)
				st = i;
			else
				f = 0;
		}
		else if (outdeg[i] + 1 == indeg[i])
		{
			if (ed == -1)
				ed = i;
			else
				f = 0;
		}
		else 
			f = 0;
	}
	if ((st == -1) != (ed == -1))
		f = 0;
	if (!f)
		return puts("NO"), 0;
	if (st == -1)
	{
		for (int i = 0; i < Base * Base; ++i)
			if (outdeg[i])
			{
				st = i;
				break;
			}
	}
	dfs(st, -1);
	if (t < n)
		return puts("NO"), 0;
	puts("YES");
	reverse(p + 1, p + 1 + n);
	putchar(buf[p[1]][0]), putchar(buf[p[1]][1]);
	for (int i = 1; i <= n; ++i)
		putchar(buf[p[i]][2]);
	puts("");
	return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details