Add independent set verification

This commit is contained in:
hal8174 2025-01-22 23:05:45 +01:00
parent 394e14cef4
commit 2f8aa9d2c6
6 changed files with 51 additions and 25 deletions

View file

@ -352,8 +352,8 @@
1055 1055
1060 1060
1061 1061
1066
1067 1067
1068
1073 1073
1074 1074
1079 1079

View file

@ -4,9 +4,9 @@
6 6
9 9
11 11
13 14
19 17
23 23
26 25
30 31
35 36

View file

@ -396,7 +396,7 @@
510 510
511 511
512 512
519 520
521 521
522 522
523 523

View file

@ -7366,7 +7366,7 @@
17273 17273
17274 17274
17276 17276
17278 17277
17279 17279
17280 17280
17282 17282
@ -7387,7 +7387,7 @@
17311 17311
17312 17312
17314 17314
17316 17315
17317 17317
17319 17319
17320 17320
@ -7399,7 +7399,7 @@
17330 17330
17332 17332
17333 17333
17336 17335
17337 17337
17341 17341
17342 17342
@ -7412,7 +7412,7 @@
17356 17356
17357 17357
17359 17359
17361 17360
17362 17362
17364 17364
17365 17365
@ -7425,11 +7425,11 @@
17376 17376
17378 17378
17379 17379
17382 17381
17383 17383
17387 17387
17388 17388
17391 17390
17392 17392
17393 17393
17395 17395
@ -7444,7 +7444,7 @@
17411 17411
17412 17412
17414 17414
17416 17415
17417 17417
17418 17418
17420 17420
@ -7453,11 +7453,11 @@
17425 17425
17427 17427
17429 17429
17431 17432
17433 17433
17435 17435
17436 17436
17438 17439
17440 17440
17441 17441
17442 17442
@ -7473,7 +7473,7 @@
17460 17460
17461 17461
17463 17463
17464 17465
17466 17466
17467 17467
17468 17468
@ -7495,12 +7495,12 @@
17499 17499
17500 17500
17502 17502
17503 17504
17505 17505
17507 17507
17508 17508
17510 17510
17512 17511
17513 17513
17514 17514
17516 17516
@ -7534,11 +7534,11 @@
17566 17566
17568 17568
17570 17570
17572 17573
17574 17574
17576 17576
17577 17577
17579 17580
17581 17581
17582 17582
17583 17583

View file

@ -1,22 +1,22 @@
35 35
43 43
58 82
93 93
133 133
134 134
151 151
154 154
172 172
187 191
204 204
205 205
226 226
227 230
275 275
277 277
287 287
290 290
297 300
341 341
345 345
346 346

View file

@ -9,6 +9,8 @@ use std::{
#[derive(Parser)] #[derive(Parser)]
struct Args { struct Args {
filename: PathBuf, filename: PathBuf,
#[arg(short, long)]
verify: bool,
} }
type NodeType = u16; type NodeType = u16;
@ -213,6 +215,26 @@ impl IndependentSet {
} }
} }
fn verify_independent_set<'a>(
set: impl IntoIterator<Item = &'a NodeType>,
td: &Baumzerlegung,
) -> bool {
let mut visited = HashSet::new();
for &v in set {
visited.insert(v);
if let Some(w_edges) = td.edges.get(&v) {
for &w in w_edges {
if visited.contains(&w) {
return false;
}
}
}
}
true
}
fn main() { fn main() {
let mut args = Args::parse(); let mut args = Args::parse();
args.filename.set_extension(""); args.filename.set_extension("");
@ -227,8 +249,12 @@ fn main() {
let mut s = s.solution().iter().copied().collect::<Vec<_>>(); let mut s = s.solution().iter().copied().collect::<Vec<_>>();
if args.verify {
assert!(verify_independent_set(&s, &td));
}
s.sort(); s.sort();
println!("{}", s.len());
for i in s { for i in s {
let _ = writeln!(bf, "{i}"); let _ = writeln!(bf, "{i}");
} }