From f110cdee18a6662d03d9b0ed7995f125f0dc5e31 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 4 Aug 2024 12:58:14 +0800 Subject: [PATCH] =?UTF-8?q?860.=20=E6=9F=93=E8=89=B2=E6=B3=95=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E4=BA=8C=E5=88=86=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/36295038/ --- AcWing/860/860.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ AcWing/860/data/17.ans | 3 +++ AcWing/860/data/17.in | 3 +++ 3 files changed, 65 insertions(+) create mode 100644 AcWing/860/860.cpp create mode 100644 AcWing/860/data/17.ans create mode 100644 AcWing/860/data/17.in diff --git a/AcWing/860/860.cpp b/AcWing/860/860.cpp new file mode 100644 index 00000000..d6156e2d --- /dev/null +++ b/AcWing/860/860.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m; +std::vector g[N]; +int color[N]; + +bool dfs(int u, int c) { + color[u] = c; + + for (int v : g[u]) { + if (~color[v]) { // 如果已经染色 + if (color[v] == c) return false; // 同色,矛盾 + } else { + if (!dfs(v, c ^ 1)) return false; + } + } + + return true; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + std::fill(std::begin(color), std::end(color), -1); + + cin >> n >> m; + + for (int i = 1, u, v; i <= m; i++) { + cin >> u >> v; + + g[u].push_back(v); + g[v].push_back(u); + } + + // 图可能不连通 + for (int i = 1; i <= n; i++) { + if (!~color[i]) { // 如果没有染色 + if (!dfs(i, 0)) { + cout << "No" << endl; + + exit(0); + } + } + } + + cout << "Yes" << endl; + + return 0; +} diff --git a/AcWing/860/data/17.ans b/AcWing/860/data/17.ans new file mode 100644 index 00000000..eeec6523 --- /dev/null +++ b/AcWing/860/data/17.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31375587f8bedb1f33f6eca3d8cee94ab70845a6dd1a7c7eeb929f4aa7dc10ab +size 3 diff --git a/AcWing/860/data/17.in b/AcWing/860/data/17.in new file mode 100644 index 00000000..05d87180 --- /dev/null +++ b/AcWing/860/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b319661c0a34865d1aa53eb98d8979074183ab34c81f889c6fa049f79428dbe7 +size 32