Submission #2960182
Source Code Expand
package main import "fmt" type Node struct { next map[int]bool checked bool values map[int]bool value int } var nodes []*Node var roots = make(map[int]bool) // 2018-08-04T00:24:54+0800 // 2018-08-04T00:41:59+0800 // 2018-08-04T01:37:57+0800 # Paused for sleeping. // 2018-08-04T13:05:41+0800 # Continue // 2018-08-04T13:30:05+0800 # Paused // 2018-08-05T23:13:36+0800 # Continue // 2018-08-05T23:49:41+0800 func main() { var N, K int fmt.Scanf("%d", &N) nodes = make([]*Node, N) for i := 0; i < N; i++ { nodes[i] = &Node{ make(map[int]bool), false, make(map[int]bool), 0, } } a, b := 0, 0 for i := 0; i < N-1; i++ { fmt.Scanf("%d%d", &a, &b) nodes[a-1].next[b-1] = true nodes[b-1].next[a-1] = true } // Building the tree. //buildTree(0) fmt.Scanf("%d", &K) for i := 0; i < K; i++ { fmt.Scanf("%d%d", &a, &b) nodes[a-1].checked = true nodes[a-1].values[b] = true nodes[a-1].value = b roots[a-1] = true } for i := range roots { if !bfs(i, i) { fmt.Println("No") return } } for i := 0; i < N; i++ { if len(nodes[i].values) == 1 { roots[i] = true for k := range nodes[i].values { nodes[i].value = k } } } for i := range roots { setValues(i, i) } fmt.Println("Yes") for i := 0; i < N; i++ { fmt.Println(nodes[i].value) } } func setValues(i, parent int) { for ii := range nodes[i].next { if roots[ii] || ii == parent { continue } nodes[ii].value = nodes[i].value + 1 roots[ii] = true setValues(ii, parent) } } func buildTree(parent int) { for i := range nodes[parent].next { delete(nodes[i].next, parent) buildTree(i) } } func bfs(root, parent int) bool { node := nodes[root] for i := range node.next { if i == parent { // Do not bread search back. continue } pv := potentialValues(node.values) if nodes[i].checked { pv := merge(pv, nodes[i].values) if len(pv) == 0 { return false } nodes[i].values = pv } else { nodes[i].values = pv } nodes[i].checked = true } for i := range node.next { if i == parent { // Do not bread search back. continue } bfs(i, root) } return true } func potentialValues(pv map[int]bool) map[int]bool { m := make(map[int]bool, len(pv)*2) for i := range pv { m[i-1] = true m[i+1] = true } return m } func merge(pv, v2 map[int]bool) map[int]bool { m := make(map[int]bool) for i := range pv { if v2[i] { m[i] = true } } return m }
Submission Info
Submission Time | |
---|---|
Task | E - Integers on a Tree |
User | zhanbei |
Language | Go (1.6) |
Score | 0 |
Code Size | 2589 Byte |
Status | WA |
Exec Time | 2127 ms |
Memory | 264912 KB |
Judge Result
Set Name | sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | binary_01.txt, binary_02.txt, hand_01.txt, hand_02.txt, hand_03.txt, kary_01.txt, kary_02.txt, kary_03.txt, line_01.txt, line_02.txt, line_03.txt, line_04.txt, line_05.txt, line_06.txt, random0_01.txt, random1_01.txt, random1_02.txt, random1_03.txt, random1_04.txt, random1_05.txt, random1_06.txt, random1_07.txt, random1_08.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random3_01.txt, random3_02.txt, random4_01.txt, random4_02.txt, random4_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, star_01.txt, star_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
binary_01.txt | TLE | 2109 ms | 90944 KB |
binary_02.txt | TLE | 2119 ms | 234056 KB |
hand_01.txt | AC | 1 ms | 512 KB |
hand_02.txt | AC | 1 ms | 512 KB |
hand_03.txt | WA | 1 ms | 512 KB |
kary_01.txt | AC | 1689 ms | 168552 KB |
kary_02.txt | TLE | 2115 ms | 169072 KB |
kary_03.txt | TLE | 2118 ms | 160368 KB |
line_01.txt | AC | 1175 ms | 31232 KB |
line_02.txt | TLE | 2126 ms | 253056 KB |
line_03.txt | TLE | 2127 ms | 254976 KB |
line_04.txt | TLE | 2111 ms | 125508 KB |
line_05.txt | AC | 968 ms | 30336 KB |
line_06.txt | TLE | 2109 ms | 112204 KB |
random0_01.txt | AC | 1489 ms | 34944 KB |
random1_01.txt | TLE | 2120 ms | 258004 KB |
random1_02.txt | TLE | 2114 ms | 155744 KB |
random1_03.txt | TLE | 2117 ms | 143484 KB |
random1_04.txt | TLE | 2113 ms | 84416 KB |
random1_05.txt | TLE | 2119 ms | 246356 KB |
random1_06.txt | TLE | 2124 ms | 248644 KB |
random1_07.txt | TLE | 2114 ms | 160484 KB |
random1_08.txt | TLE | 2111 ms | 51584 KB |
random2_01.txt | TLE | 2121 ms | 257616 KB |
random2_02.txt | TLE | 2125 ms | 264912 KB |
random2_03.txt | TLE | 2125 ms | 252880 KB |
random2_04.txt | TLE | 2114 ms | 156128 KB |
random2_05.txt | TLE | 2113 ms | 84544 KB |
random2_06.txt | TLE | 2106 ms | 48644 KB |
random3_01.txt | TLE | 2121 ms | 251936 KB |
random3_02.txt | TLE | 2113 ms | 84800 KB |
random4_01.txt | TLE | 2124 ms | 249424 KB |
random4_02.txt | TLE | 2120 ms | 257748 KB |
random4_03.txt | TLE | 2121 ms | 250576 KB |
sample_01.txt | AC | 1 ms | 512 KB |
sample_02.txt | AC | 1 ms | 512 KB |
sample_03.txt | AC | 1 ms | 512 KB |
star_01.txt | TLE | 2109 ms | 82500 KB |
star_02.txt | AC | 1273 ms | 38144 KB |