-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10054.go
67 lines (59 loc) · 1018 Bytes
/
10054.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// UVa 10054 - The Necklace
package main
import (
"fmt"
"io"
"os"
)
const max = 50
var (
out io.WriteCloser
matrix [][]int
degree []int
)
func euler(v int) {
for i := range matrix {
if matrix[v][i] != 0 {
matrix[v][i]--
matrix[i][v]--
euler(i)
fmt.Fprintln(out, i, v)
}
}
}
func solve(v int) {
for _, vi := range degree {
if vi%2 != 0 {
fmt.Fprintln(out, "some beads may be lost")
return
}
}
euler(v)
}
func main() {
in, _ := os.Open("10054.in")
defer in.Close()
out, _ = os.Create("10054.out")
defer out.Close()
var t, n, l, r int
fmt.Fscanf(in, "%d", &t)
for kase := 1; kase <= t; kase++ {
matrix = make([][]int, max+1)
for i := range matrix {
matrix[i] = make([]int, max+1)
}
degree = make([]int, max+1)
for fmt.Fscanf(in, "%d", &n); n > 0; n-- {
fmt.Fscanf(in, "%d%d", &l, &r)
matrix[l][r]++
matrix[r][l]++
degree[l]++
degree[r]++
}
if kase > 1 {
fmt.Fprintln(out)
}
fmt.Fprintf(out, "Case #%d\n", kase)
solve(r)
}
}