From 884d1b4ee44dfac03cc58cad7f504a70503731c4 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Jun 2022 16:28:40 +0800 Subject: [PATCH] =?UTF-8?q?P4151=20[WC2011]=E6=9C=80=E5=A4=A7XOR=E5=92=8C?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/77021578 --- Luogu/P4151/P4151.cpp | 69 ++++++++++++++++++++++++++++++++++++ Luogu/P4151/data/P4151_1.in | 3 ++ Luogu/P4151/data/P4151_1.out | 3 ++ 3 files changed, 75 insertions(+) create mode 100644 Luogu/P4151/P4151.cpp create mode 100644 Luogu/P4151/data/P4151_1.in create mode 100644 Luogu/P4151/data/P4151_1.out diff --git a/Luogu/P4151/P4151.cpp b/Luogu/P4151/P4151.cpp new file mode 100644 index 00000000..236a23b7 --- /dev/null +++ b/Luogu/P4151/P4151.cpp @@ -0,0 +1,69 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 50005; + +int n, m; +bool vis[N]; +unsigned long long p[N], dep[N], ans; +std::vector> g[N]; + +inline void insert(unsigned long long x) { + for (int i = 60; ~i; i--) { + if (x & (1ull << i)) { + if (p[i]) { + x ^= p[i]; + } else { + p[i] = x; + return; + } + } + } +} + +void dfs(int u, unsigned long long sum) { + vis[u] = true; + dep[u] = sum; + + for (auto e : g[u]) { + int v = e.first; + unsigned long long w = e.second; + + if (vis[v]) insert(sum ^ dep[v] ^ w); + else dfs(v, sum ^ w); + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= m; i++) { + int s, t; + unsigned long long d; + + cin >> s >> t >> d; + + g[s].push_back(std::make_pair(t, d)); + g[t].push_back(std::make_pair(s, d)); + } + + dfs(1, 0); + + ans = dep[n]; + + for (int i = 60; ~i; i--) { + if ((ans ^ p[i]) > ans) ans ^= p[i]; + } + + cout << ans << endl; + + return 0; +} diff --git a/Luogu/P4151/data/P4151_1.in b/Luogu/P4151/data/P4151_1.in new file mode 100644 index 00000000..91d2b6e7 --- /dev/null +++ b/Luogu/P4151/data/P4151_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a2b2226e1d06a73ded6334fa900ae550bb366758170dcf3ace9dcfb74c469cf +size 10659 diff --git a/Luogu/P4151/data/P4151_1.out b/Luogu/P4151/data/P4151_1.out new file mode 100644 index 00000000..5a77f7cb --- /dev/null +++ b/Luogu/P4151/data/P4151_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4f04901f6aa37f0ac9c0b96152b3734d7d799a3ac7b3b6c00bbeb569c723abd +size 6