(&self)
| 108 | } |
| 109 | |
| 110 | pub fn check(&self) -> Result<(), String> { |
| 111 | if let Some(cycle) = self.cycle() { |
| 112 | let mut first = -1; |
| 113 | let mut last = -1; |
| 114 | for &v in cycle { |
| 115 | if first == -1 { |
| 116 | first = v as i32; |
| 117 | } |
| 118 | last = v as i32; |
| 119 | } |
| 120 | if first != last { |
| 121 | return Err(format!( |
| 122 | "cycle begins with {} and ends with {}", |
| 123 | first, last |
| 124 | )); |
| 125 | } |
| 126 | } |
| 127 | Ok(()) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | impl EdgeWeightedDirectedCycle { |