diff --git a/2017/SEPT.md b/2017/SEPT.md index 2ba3db2..d333613 100644 --- a/2017/SEPT.md +++ b/2017/SEPT.md @@ -13,7 +13,7 @@ | [SEPT17](https://www.codechef.com/SEPT17) | [MINPERM](https://www.codechef.com/SEPT17/problems/MINPERM) | ★★ | | | | [![image](../img/GH.png)](SEPT/SEPT17/MINPERM/MINPERM.py) [![image](../img/CC.png)](https://www.codechef.com/viewsolution/15236776) (100 pts) [![image](../img/AC.png)](#) | | [SEPT17](https://www.codechef.com/SEPT17) | [CHEFPDIG](https://www.codechef.com/SEPT17/problems/CHEFPDIG) | ★★★ | | | | | | [SEPT17](https://www.codechef.com/SEPT17) | [SEACO](https://www.codechef.com/SEPT17/problems/SEACO) | ★★★★ | | [![image](../img/CC.png)](https://www.codechef.com/viewsolution/15338761) [![image](../img/GH.png)](SEPT/SEPT17/SEACO/SEACO.cpp) (100 pts) [![image](../img/AC.png)](#) | | | -| [SEPT17](https://www.codechef.com/SEPT17) | [FILLMTR](https://www.codechef.com/SEPT17/problems/FILLMTR) | ★★★★ | | [![image](../img/CC.png)](https://www.codechef.com/viewsolution/15243260) [![image](../img/GH.png)](SEPT/SEPT17/FILLMTR/FILLMTR.cpp) (100 pts) [![image](../img/AC.png)](#) | | | +| [SEPT17](https://www.codechef.com/SEPT17) | [FILLMTR](https://www.codechef.com/SEPT17/problems/FILLMTR) | ★★★★ | | [![image](../img/CC.png)](https://www.codechef.com/viewsolution/15243260) [![image](../img/GH.png)](SEPT/SEPT17/FILLMTR/FILLMTR.cpp) (100 pts) [![image](../img/AC.png)](#) | | [![image](../img/GH.png)](SEPT/SEPT17/FILLMTR/FILLMTR.py) [![image](../img/CC.png)](https://www.codechef.com/viewsolution/15258986) (100 pts) [![image](../img/AC.png)](#) | | [SEPT17](https://www.codechef.com/SEPT17) | [WEASELTX](https://www.codechef.com/SEPT17/problems/WEASELTX) | ★★★★★ | | | | | | [SEPT17](https://www.codechef.com/SEPT17) | [SEAFUNC](https://www.codechef.com/SEPT17/problems/SEAFUNC) | ★★★★★ | | | | | | [SEPT17](https://www.codechef.com/SEPT17) | [SUMCUBE](https://www.codechef.com/SEPT17/problems/SUMCUBE) | ★★★★★★ | | | | | diff --git a/2017/SEPT/SEPT17/FILLMTR/FILLMTR.py b/2017/SEPT/SEPT17/FILLMTR/FILLMTR.py new file mode 100644 index 0000000..f128d22 --- /dev/null +++ b/2017/SEPT/SEPT17/FILLMTR/FILLMTR.py @@ -0,0 +1,67 @@ +def main(): + t = int(raw_input()) + while t: + t -= 1 + n = map(int, raw_input().split()) + q = n[1] + n = n[0] + queries = [] + good = [] + ans = 1 + for i in range(n): + good.append('a') + good.append('a') + for i in range(q): + a = map(int, raw_input().split()) + queries.append(a) + queries.sort() + for i in queries: + if(i[0] == i[1] and i[2] == 1): + ans = 0 + break + elif(i[0] == i[1] and i[2] == 0): + continue + else: + if(good[i[0]] == 'a' and good[i[1]] == 'a'): + if(i[2] == 1): + good[i[0]] = 1 + good[i[1]] = 0 + else: + good[i[0]] = 0 + good[i[1]] = 0 + elif(good[i[0]] != 'a' and good[i[1]] == 'a'): + if(good[i[0]] == 1): + if(i[2] == 1): + good[i[1]] = 0 + else: + good[i[1]] = 1 + else: + if(i[2] == 1): + good[i[1]] = 1 + else: + good[i[1]] = 0 + elif(good[i[0]] == 'a' and good[i[1]] != 'a'): + if(good[i[1]] == 1): + if(i[2] == 1): + good[i[0]] = 0 + else: + good[i[0]] = 1 + else: + if(i[2] == 1): + good[i[0]] = 1 + else: + good[i[0]] = 0 + else: + if(abs(good[i[0]] - good[i[1]]) == i[2]): + continue + else: + ans = 0 + break + if(ans): + print "yes" + else: + print "no" + + +if __name__ == '__main__': + main()