Compare commits
2 commits
9ec5e10c0b
...
5a3525a9ce
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a3525a9ce | |||
| 67fcde4309 |
6 changed files with 77 additions and 74 deletions
|
|
@ -163,6 +163,7 @@ struct Args {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let total_start = std::time::Instant::now();
|
||||
let args = Args::parse();
|
||||
|
||||
let graph = parse(args.filename);
|
||||
|
|
@ -207,4 +208,5 @@ fn main() {
|
|||
println!("{}", n + 1);
|
||||
}
|
||||
}
|
||||
eprintln!("Total time: {:?}", total_start.elapsed());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,10 +77,11 @@ impl Graph {
|
|||
self.vertices[(self.vertices.len() - n)..].iter()
|
||||
}
|
||||
|
||||
fn get_vertex_with_degree_greater(&self, min_degree: u16) -> Option<u16> {
|
||||
fn get_vertex_with_max_degree_greater_equal(&self, min_degree: u16) -> Option<u16> {
|
||||
self.vertices
|
||||
.iter()
|
||||
.find(|&v| v.edges.len() >= min_degree as usize)
|
||||
.max_by_key(|&v| v.edges.len())
|
||||
.filter(|&v| v.edges.len() >= min_degree as usize)
|
||||
.map(|v| v.name)
|
||||
}
|
||||
|
||||
|
|
@ -107,12 +108,12 @@ impl Graph {
|
|||
}
|
||||
|
||||
pub fn binary_vertex(graph: &mut Graph, k: u16) -> Option<Vec<u16>> {
|
||||
let vertex = match graph.get_vertex_with_degree_greater(2) {
|
||||
let vertex = match graph.get_vertex_with_max_degree_greater_equal(2) {
|
||||
Some(vertex) => vertex,
|
||||
None => {
|
||||
return {
|
||||
let mut c = 0;
|
||||
while let Some(vertex) = graph.get_vertex_with_degree_greater(1) {
|
||||
while let Some(vertex) = graph.get_vertex_with_max_degree_greater_equal(1) {
|
||||
graph.remove_vertex(vertex);
|
||||
c += 1;
|
||||
}
|
||||
|
|
@ -195,7 +196,7 @@ pub fn reduction(graph: &mut Graph, k: u16) -> Option<Vec<u16>> {
|
|||
}
|
||||
|
||||
r
|
||||
} else if let Some(vertex) = graph.get_vertex_with_degree_greater(2) {
|
||||
} else if let Some(vertex) = graph.get_vertex_with_max_degree_greater_equal(2) {
|
||||
graph.remove_vertex(vertex);
|
||||
|
||||
match reduction(graph, k - 1) {
|
||||
|
|
@ -347,7 +348,7 @@ pub fn reduction2(graph: &mut Graph, k: u16) -> Option<Vec<u16>> {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(vertex) = graph.get_vertex_with_degree_greater(3) {
|
||||
} else if let Some(vertex) = graph.get_vertex_with_max_degree_greater_equal(3) {
|
||||
if k < 1 {
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
35
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
7
|
||||
6
|
||||
8
|
||||
11
|
||||
12
|
||||
9
|
||||
10
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
27
|
||||
25
|
||||
28
|
||||
29
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
30
|
||||
32
|
||||
|
|
@ -24,6 +23,7 @@
|
|||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
|
|
@ -34,9 +34,9 @@
|
|||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
58
|
||||
60
|
||||
63
|
||||
65
|
||||
67
|
||||
|
|
@ -50,16 +50,16 @@
|
|||
81
|
||||
82
|
||||
83
|
||||
84
|
||||
86
|
||||
87
|
||||
89
|
||||
90
|
||||
91
|
||||
93
|
||||
94
|
||||
95
|
||||
97
|
||||
99
|
||||
98
|
||||
101
|
||||
104
|
||||
105
|
||||
|
|
|
|||
|
|
@ -5,44 +5,40 @@
|
|||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
28
|
||||
27
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
49
|
||||
48
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
59
|
||||
60
|
||||
61
|
||||
|
|
@ -51,11 +47,14 @@
|
|||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
|
|
@ -63,11 +62,12 @@
|
|||
84
|
||||
85
|
||||
86
|
||||
91
|
||||
87
|
||||
88
|
||||
89
|
||||
90
|
||||
92
|
||||
93
|
||||
94
|
||||
95
|
||||
96
|
||||
97
|
||||
98
|
||||
99
|
||||
100
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
112
|
||||
1
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
8
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
25
|
||||
27
|
||||
28
|
||||
30
|
||||
|
|
@ -19,30 +21,34 @@
|
|||
32
|
||||
33
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
43
|
||||
41
|
||||
42
|
||||
44
|
||||
45
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
58
|
||||
59
|
||||
55
|
||||
56
|
||||
57
|
||||
60
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
68
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
|
|
@ -51,63 +57,57 @@
|
|||
84
|
||||
86
|
||||
87
|
||||
90
|
||||
88
|
||||
89
|
||||
92
|
||||
93
|
||||
94
|
||||
96
|
||||
97
|
||||
98
|
||||
100
|
||||
102
|
||||
103
|
||||
104
|
||||
105
|
||||
106
|
||||
107
|
||||
108
|
||||
109
|
||||
110
|
||||
111
|
||||
112
|
||||
113
|
||||
114
|
||||
115
|
||||
116
|
||||
118
|
||||
119
|
||||
121
|
||||
120
|
||||
122
|
||||
123
|
||||
124
|
||||
125
|
||||
126
|
||||
127
|
||||
128
|
||||
130
|
||||
131
|
||||
133
|
||||
134
|
||||
136
|
||||
132
|
||||
138
|
||||
139
|
||||
141
|
||||
142
|
||||
143
|
||||
144
|
||||
145
|
||||
146
|
||||
147
|
||||
148
|
||||
149
|
||||
150
|
||||
152
|
||||
151
|
||||
153
|
||||
154
|
||||
155
|
||||
156
|
||||
157
|
||||
158
|
||||
159
|
||||
160
|
||||
163
|
||||
164
|
||||
166
|
||||
162
|
||||
168
|
||||
169
|
||||
170
|
||||
172
|
||||
173
|
||||
174
|
||||
175
|
||||
176
|
||||
177
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue