mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 17:28:47 +00:00
parent
821fa6c8db
commit
7e70996308
68
LibreOJ/109/109.go
Normal file
68
LibreOJ/109/109.go
Normal file
@ -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
|
||||
}
|
BIN
LibreOJ/109/data/0.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/109/data/0.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/109/data/0.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/109/data/0.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/109/data/1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/109/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/109/data/1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/109/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user