Skip to content

Commit

Permalink
CF1176E n/2 点覆盖
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessCheng committed Feb 15, 2023
1 parent 1babfec commit 53262fb
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
49 changes: 49 additions & 0 deletions main/1100-1199/1176E.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"bufio"
. "fmt"
"io"
)

// https://space.bilibili.com/206214
func CF1176E(_r io.Reader, _w io.Writer) {
in := bufio.NewReader(_r)
out := bufio.NewWriter(_w)
defer out.Flush()

var T, n, m, v, w int
for Fscan(in, &T); T > 0; T-- {
Fscan(in, &n, &m)
g := make([][]int, n+1)
for ; m > 0; m-- {
Fscan(in, &v, &w)
g[v] = append(g[v], w)
g[w] = append(g[w], v)
}
vis := make([]bool, len(g))
a := [2][]int{}
var f func(int, int)
f = func(v, d int) {
vis[v] = true
a[d] = append(a[d], v)
for _, w := range g[v] {
if !vis[w] {
f(w, d^1)
}
}
}
f(1, 0)
ans := a[0]
if len(a[0]) > len(a[1]) {
ans = a[1]
}
Fprintln(out, len(ans))
for _, v := range ans {
Fprint(out, v, " ")
}
Fprintln(out)
}
}

//func main() { CF1176E(os.Stdin, os.Stdout) }
37 changes: 37 additions & 0 deletions main/1100-1199/1176E_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"github.com/EndlessCheng/codeforces-go/main/testutil"
"testing"
)

// https://codeforces.com/contest/1176/problem/E
// https://codeforces.com/problemset/status/1176/problem/E
func TestCF1176E(t *testing.T) {
// just copy from website
rawText := `
inputCopy
2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
6 8
2 5
5 4
4 3
4 1
1 3
2 3
2 6
5 6
outputCopy
2
1 3
3
4 3 6`
testutil.AssertEqualCase(t, rawText, 0, CF1176E)
}

0 comments on commit 53262fb

Please sign in to comment.