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
use crate::Canonize;
#[derive(Ord, PartialOrd, PartialEq, Eq, Clone, Debug)]
pub struct Graph {
adj: Vec<Vec<usize>>,
}
impl Graph {
pub fn new(n: usize, edges: &[(usize, usize)]) -> Self {
let mut adj = vec![Vec::new(); n];
for &(u, v) in edges {
adj[u].push(v);
adj[v].push(u);
}
for nbrs in &mut adj {
nbrs.sort()
}
Graph { adj }
}
}
impl Canonize for Graph {
fn size(&self) -> usize {
self.adj.len()
}
fn apply_morphism(&self, perm: &[usize]) -> Self {
let mut adj = vec![Vec::new(); self.size()];
for (i, nbrs) in self.adj.iter().enumerate() {
adj[perm[i]] = nbrs.iter().map(|&u| perm[u]).collect();
adj[perm[i]].sort();
}
Graph { adj }
}
fn invariant_neighborhood(&self, u: usize) -> Vec<Vec<usize>> {
vec![self.adj[u].clone()]
}
}