diff --git a/Luogu/P1341/P1341.cpp b/Luogu/P1341/P1341.cpp new file mode 100644 index 00000000..6c1913f8 --- /dev/null +++ b/Luogu/P1341/P1341.cpp @@ -0,0 +1,78 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1005; + +int n, cnt, s, t, deg[N], ans[N]; +int g[N][N]; +std::set nodes; + +void dfs(char u) { + for (int i = 1; i <= 128; i++) { + if (g[u][i]) { + g[u][i]--; + g[i][u]--; + + dfs(i); + } + } + + ans[++cnt] = u; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + char u, v; + + cin >> u >> v; + + g[u][v]++, g[v][u]++; + deg[u]++, deg[v]++; + + nodes.insert(u); + nodes.insert(v); + } + + int x = 0; + + t = *nodes.rbegin(); + + for (const char &node : nodes) { + if (deg[node] & 1) { + x++; + + if (!s) s = node; + } + } + + if (!s) s = *nodes.begin(); + + if (x && x != 2) { + cout << "No Solution" << endl; + + exit(0); + } + + dfs(s); + + if (cnt <= n) { + cout << "No Solution" << endl; + } else { + for (int i = cnt; i; i--) { + cout << (char)(ans[i]); + } + cout << endl; + } + + return 0; +} diff --git a/Luogu/P1341/data/P1341_2.in b/Luogu/P1341/data/P1341_2.in new file mode 100644 index 00000000..a02d2ba8 --- /dev/null +++ b/Luogu/P1341/data/P1341_2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee8bf39b17d5b609e7118640451c453ce75e88355f5338bf598b3c4ebc6978b1 +size 7 diff --git a/Luogu/P1341/data/P1341_2.out b/Luogu/P1341/data/P1341_2.out new file mode 100644 index 00000000..71d52682 --- /dev/null +++ b/Luogu/P1341/data/P1341_2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d90352c0506054508147b7430fd3100ebd172335d99a946ab378d343145b825 +size 4