From 4ffc98b8547b30d02400464d08147018fb2a917f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 25 Aug 2022 20:46:19 +0800 Subject: [PATCH] =?UTF-8?q?#1497.=20=E6=A0=91(tree)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/55682 --- S2OJ/1497/1497.cpp | 71 +++++++++++++++++++++++++++++++++++++ S2OJ/1497/data/data1.in | 3 ++ S2OJ/1497/data/data1.out | 3 ++ S2OJ/1497/data/data2.in | 3 ++ S2OJ/1497/data/data2.out | 3 ++ S2OJ/1497/data/data3.in | 3 ++ S2OJ/1497/data/data3.out | 3 ++ S2OJ/1497/data/data4.in | 3 ++ S2OJ/1497/data/data4.out | 3 ++ S2OJ/1497/data/data5.in | 3 ++ S2OJ/1497/data/data5.out | 3 ++ S2OJ/1497/data/data6.in | 3 ++ S2OJ/1497/data/data6.out | 3 ++ S2OJ/1497/data/problem.conf | 3 ++ 14 files changed, 110 insertions(+) create mode 100644 S2OJ/1497/1497.cpp create mode 100644 S2OJ/1497/data/data1.in create mode 100644 S2OJ/1497/data/data1.out create mode 100644 S2OJ/1497/data/data2.in create mode 100644 S2OJ/1497/data/data2.out create mode 100644 S2OJ/1497/data/data3.in create mode 100644 S2OJ/1497/data/data3.out create mode 100644 S2OJ/1497/data/data4.in create mode 100644 S2OJ/1497/data/data4.out create mode 100644 S2OJ/1497/data/data5.in create mode 100644 S2OJ/1497/data/data5.out create mode 100644 S2OJ/1497/data/data6.in create mode 100644 S2OJ/1497/data/data6.out create mode 100644 S2OJ/1497/data/problem.conf diff --git a/S2OJ/1497/1497.cpp b/S2OJ/1497/1497.cpp new file mode 100644 index 00000000..061e8fc0 --- /dev/null +++ b/S2OJ/1497/1497.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e6 + 5; + +int n, m, a, b, ans; +unsigned long long sum[N]; +std::vector> g[N]; +std::map map; +std::set set; + +void dfs(int u, int f, unsigned long long s) { + sum[u] = sum[f] ^ s; + + for (auto e : g[u]) { + int v = e.first; + unsigned long long w = e.second; + + if (v == f) continue; + + dfs(v, u, w); + } +} + +signed main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + std::mt19937_64 rand(std::chrono::system_clock::now().time_since_epoch().count()); + + cin >> n >> m; + + for (int i = 1; i < n; i++) { + int u, v, w; + + cin >> u >> v >> w; + + if (!map.count(w)) map[w] = rand(); + set.insert(map[w]); + g[u].emplace_back(v, map[w]); + g[v].emplace_back(u, map[w]); + } + + dfs(1, 0, 0); + + cin >> a >> b; + + while (m--) { + int x = a % n + 1, + y = b % n + 1; + + unsigned long long s = sum[x] ^ sum[y]; + + if (s == 0 || set.count(s)) ans++; + + a = static_cast(a) * 666073 % 1000000007; + b = static_cast(b) * 233 % 998244353; + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1497/data/data1.in b/S2OJ/1497/data/data1.in new file mode 100644 index 00000000..280c2fd1 --- /dev/null +++ b/S2OJ/1497/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb749812f6a88e1ba467ae9e64d8fd8b39e31cdd9a50974a1f9def80e0ded2f9 +size 25629 diff --git a/S2OJ/1497/data/data1.out b/S2OJ/1497/data/data1.out new file mode 100644 index 00000000..ca267b30 --- /dev/null +++ b/S2OJ/1497/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2 +size 2 diff --git a/S2OJ/1497/data/data2.in b/S2OJ/1497/data/data2.in new file mode 100644 index 00000000..47dba762 --- /dev/null +++ b/S2OJ/1497/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98ed7f715de793f650222086e4b61609eeb63ec869e9f38b4d62691f09acdf89 +size 1388724 diff --git a/S2OJ/1497/data/data2.out b/S2OJ/1497/data/data2.out new file mode 100644 index 00000000..bb31471a --- /dev/null +++ b/S2OJ/1497/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a62cf402cd3396aa00f55f892f4545f308f74d01c8caa0f2837b1982f821595 +size 3 diff --git a/S2OJ/1497/data/data3.in b/S2OJ/1497/data/data3.in new file mode 100644 index 00000000..06b6cd70 --- /dev/null +++ b/S2OJ/1497/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:396add9bbe2f72661278be6a5c5fbadfc6f159be2845330f6939b285904cc9d9 +size 1385902 diff --git a/S2OJ/1497/data/data3.out b/S2OJ/1497/data/data3.out new file mode 100644 index 00000000..b48632ca --- /dev/null +++ b/S2OJ/1497/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd5fa6e75f0ddfcd9ff32e0a2297554cd81188f177f14d7ce416310efa0b5c77 +size 3 diff --git a/S2OJ/1497/data/data4.in b/S2OJ/1497/data/data4.in new file mode 100644 index 00000000..46d0a4dc --- /dev/null +++ b/S2OJ/1497/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e2b0dba48245f6370356cf87cfa3af48389b0101df57d8f87274f4ca3c46627 +size 15766349 diff --git a/S2OJ/1497/data/data4.out b/S2OJ/1497/data/data4.out new file mode 100644 index 00000000..b48632ca --- /dev/null +++ b/S2OJ/1497/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd5fa6e75f0ddfcd9ff32e0a2297554cd81188f177f14d7ce416310efa0b5c77 +size 3 diff --git a/S2OJ/1497/data/data5.in b/S2OJ/1497/data/data5.in new file mode 100644 index 00000000..931206de --- /dev/null +++ b/S2OJ/1497/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d00eeb21053c234f342c0782a77d9e2b1dc48d0457a8873f869e9f106acbca0 +size 15892206 diff --git a/S2OJ/1497/data/data5.out b/S2OJ/1497/data/data5.out new file mode 100644 index 00000000..38c32322 --- /dev/null +++ b/S2OJ/1497/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be4ba010e48e7d5c7c60457e7f40538407a26f4ead94b392beff67a3a5546b8a +size 3 diff --git a/S2OJ/1497/data/data6.in b/S2OJ/1497/data/data6.in new file mode 100644 index 00000000..9b54233d --- /dev/null +++ b/S2OJ/1497/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4197d02b0b905f2628750cecf31afff6f86be6660f40f67809a3d410644a0b0e +size 15745972 diff --git a/S2OJ/1497/data/data6.out b/S2OJ/1497/data/data6.out new file mode 100644 index 00000000..da11d17b --- /dev/null +++ b/S2OJ/1497/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e313ad220a460ae9fb1fa62d4c7dc46759398470ac2eba5d56acfd7565d07a2 +size 8 diff --git a/S2OJ/1497/data/problem.conf b/S2OJ/1497/data/problem.conf new file mode 100644 index 00000000..b13f5ce7 --- /dev/null +++ b/S2OJ/1497/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b62fe8129a873b9c17f5e5de75ba6b9a94a79dd9fa62c9b02681d43d00ef359 +size 176