#Lutece1647. 酌贪泉而觉爽, 处涸辙以犹欢。
酌贪泉而觉爽, 处涸辙以犹欢。
Migrated from Lutece 1647 酌贪泉而觉爽, 处涸辙以犹欢。
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
在,你会学到众多的,像,,,等,但是,这里,我们考虑一种名叫的东西,它的作用与前面的不太一样,在这里,是将一个01串,映射为另一个等长的01串。
的映射规则有条,在下面给出;同时,每计算一个需要一定的时间,现在给你初始的01串,其长度为,并且元素全为0,即,问你,至少需要多长的时间,可以通过将变为,长度也为,且元素全为1(即)
Input
首行两个整数.
接下来行,每行包括两个01串(长度为)和一个整数,表示经过变为需要 的时间
Output
如果不能得到,输出-1;
否则输出将经过变为所需最少时间。
Samples
3 5
000 110 2
000 010 4
000 101 2
110 111 1
000 111 3
3
Resources
2017 UESTC Training for Graph Theory