Exact inference in structured prediction