string search, kmp & maxflow