-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23.go
66 lines (64 loc) · 1.66 KB
/
23.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
package main
import "bufio"
import "os"
import "strings"
import "fmt"
import "slices"
func main() {
var scanner = bufio.NewScanner(os.Stdin)
type conn struct {c1, c2 string}
var conns = make(map[conn]bool)
var compSet = make(map[string]bool)
for scanner.Scan() {
var c = strings.Split(scanner.Text(), "-")
conns[conn{c[0], c[1]}] = true
conns[conn{c[1], c[0]}] = true
compSet[c[0]] = true
compSet[c[1]] = true
}
var comps []string
for c, _ := range compSet { comps = append(comps, c) }
var tconns = 0
for i := 0; i < len(comps) - 2; i++ {
for j := i + 1; j < len(comps) - 1; j++ {
for k := j + 1; k < len(comps); k++ {
var c1, c2, c3 = comps[i], comps[j], comps[k]
if conns[conn{c1, c2}] && conns[conn{c2, c3}] && conns[conn{c1, c3}] &&
(c1[0] == 't' || c2[0] == 't' || c3[0] == 't') {
tconns++
}
}
}
}
fmt.Print(tconns)
var foreach = func (comp string, process func (second string)) {
for _, second := range comps {
if second != comp && conns[conn{comp, second}] {
process(second)
}
}
}
var largest = make(map[string]bool)
for _, comp := range comps {
foreach(comp, func (second string) {
var lan = make(map[string]bool)
lan[comp] = true
lan[second] = true
foreach(comp, func (second string) {
if lan[second] { return }
var all = true
foreach(second, func (_ string) {
for lc, _ := range lan {
if !conns[conn{second, lc}] { all = false }
}
})
if all { lan[second] = true }
})
if len(lan) > len(largest) { largest = lan }
})
}
var list []string
for c, _ := range largest { list = append(list, c) }
slices.Sort(list)
fmt.Println("", strings.Join(list, ","))
}