(g: &dyn IGraph)
| 27 | |
| 28 | impl Bipartite { |
| 29 | pub fn new(g: &dyn IGraph) -> Self { |
| 30 | let mut tc = Self { |
| 31 | marked: vec![false; g.V()], |
| 32 | color: vec![false; g.V()], |
| 33 | edge_to: vec![0; g.V()], |
| 34 | cycle: None, |
| 35 | is_bipartite: true, |
| 36 | }; |
| 37 | |
| 38 | for s in 0..g.V() { |
| 39 | if !tc.marked[s] { |
| 40 | tc.dfs(g, s); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | tc |
| 45 | } |
| 46 | |
| 47 | pub fn is_bipartite(&self) -> bool { |
| 48 | self.is_bipartite |