From 7e709963087dac82be11373b358526f52a5fc31f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Jun 2022 18:02:56 +0800 Subject: [PATCH] =?UTF-8?q?#109.=20=E5=B9=B6=E6=9F=A5=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1479164 --- LibreOJ/109/109.go | 68 ++++++++++++++++++++++++++++++++++++++++++ LibreOJ/109/data/0.in | 3 ++ LibreOJ/109/data/0.out | 3 ++ LibreOJ/109/data/1.in | 3 ++ LibreOJ/109/data/1.out | 3 ++ 5 files changed, 80 insertions(+) create mode 100644 LibreOJ/109/109.go create mode 100644 LibreOJ/109/data/0.in create mode 100644 LibreOJ/109/data/0.out create mode 100644 LibreOJ/109/data/1.in create mode 100644 LibreOJ/109/data/1.out diff --git a/LibreOJ/109/109.go b/LibreOJ/109/109.go new file mode 100644 index 00000000..7d01d37f --- /dev/null +++ b/LibreOJ/109/109.go @@ -0,0 +1,68 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +const mod = 998244353 + +var fa [4000005]int + +func main() { + scanner := bufio.NewScanner(os.Stdin) + + scanner.Scan() + raw := strings.Split(scanner.Text(), " ") + n, _ := strconv.Atoi(raw[0]) + m, _ := strconv.Atoi(raw[1]) + + for i := 1; i <= n; i++ { + fa[i] = i + } + + ans := 0 + + for i := 1; i <= m; i++ { + scanner.Scan() + raw := strings.Split(scanner.Text(), " ") + op, _ := strconv.Atoi(raw[0]) + u, _ := strconv.Atoi(raw[1]) + v, _ := strconv.Atoi(raw[2]) + + if op == 0 { + merge(u, v) + } else { // op == 1 + ans <<= 1 + ans |= bool2int(find(u) == find(v)) + ans %= mod + } + } + + fmt.Println(ans) +} + +func find(x int) int { + if fa[x] == x { + return x + } + + fa[x] = find(fa[x]) + + return fa[x] +} + +func merge(x int, y int) { + fa[find(x)] = find(y) +} + +func bool2int(x bool) int { + if x { + return 1 + } + + return 0 +} diff --git a/LibreOJ/109/data/0.in b/LibreOJ/109/data/0.in new file mode 100644 index 00000000..67ac29df --- /dev/null +++ b/LibreOJ/109/data/0.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:026c55efbd9b619fd204576b9887900239836b131e3337a6a668bb05f6dd331d +size 69307325 diff --git a/LibreOJ/109/data/0.out b/LibreOJ/109/data/0.out new file mode 100644 index 00000000..a79cbc2c --- /dev/null +++ b/LibreOJ/109/data/0.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb724a80ef3f67f88e997343343c6659f56f3508823853cc54dd15ecd1d44198 +size 11 diff --git a/LibreOJ/109/data/1.in b/LibreOJ/109/data/1.in new file mode 100644 index 00000000..08c8511e --- /dev/null +++ b/LibreOJ/109/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:748185e22033038cd4d00a1899bbc8ced89f301833413b0332e75cacf839a738 +size 142948024 diff --git a/LibreOJ/109/data/1.out b/LibreOJ/109/data/1.out new file mode 100644 index 00000000..9587168c --- /dev/null +++ b/LibreOJ/109/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82c9932aa05d55c0f0e5f316bdb8b0f1d8acc261f80af8c6ea891659fdaad77a +size 11