Problem:


Score : 700 points

Problem Statement

Snuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges.
This graph was connected and contained no parallel edges or self-loops.

One day, Snuke broke this graph.
Fortunately, he remembered Q clues about the graph.
The i-th clue (0 \leq i \leq Q-1) is represented as integers A_i,B_i,C_i and means the following:

If C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.

If C_i=1: there were two or more simple paths from Vertex A_i to B_i.

Snuke is not sure if his memory is correct, and worried whether there is a graph that matches these Q clues.
Determine if there exists a graph that matches Snuke's memory.

Constraints

2 \leq N \leq 10^5

N-1 \leq M \leq N \times (N-1)/2

1 \leq Q \leq 10^5

0 \leq A_i,B_i \leq N-1

A_i \neq B_i

0 \leq C_i \leq 1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M Q
A_0 B_0 C_0
A_1 B_1 C_1
\vdots
A_{Q-1} B_{Q-1} C_{Q-1}

Output

If there exists a graph that matches Snuke's memory, print Yes; otherwise, print No.

Sample Input 1

5 5 3
0 1 0
1 2 1
2 3 0

Sample Output 1

Yes

For example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This graph matches the clues.

Sample Input 2

4 4 3
0 1 0
1 2 1
2 3 0

Sample Output 2

No

Sample Input 3

10 9 9
7 6 0
4 5 1
9 7 0
2 9 0
2 3 0
4 1 0
8 0 0
9 1 0
3 0 0

Sample Output 3

No



Sample input:
5 5 3
0 1 0
1 2 1
2 3 0


Sample output:
Yes

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3

### @file up.py
### @brief
### @author Yusuke Matsunaga (松永 裕介)
###
### Copyright (C) 2019 Yusuke Matsunaga
### All rights reserved.

n_str, m_str, q_str = input().split()
n = int(n_str)
m = int(m_str)
q = int(q_str)

# single path と multi path のペアを作る．
single_pair = []
multi_pair = []
for i in range(q) :
    a_str, b_str, c_str = input().split()
    a = int(a_str)
    b = int(b_str)
    c = int(c_str)
    # 正規化しておく
    if b < a :
        tmp = a
        a = b
        b = tmp
    if c :
        # multi path
        multi_pair.append( (a, b) )
    else :
        # single path
        single_pair.append( (a, b) )

# 特別なケース
if m == n - 1 and len(multi_pair) > 0 :
    # M = N - 1 は木構造しかありえない．
    print('No')
    exit(0)

# single path のグループを作る．
adj_list = [ [] for i in range(n) ]
for a, b in single_pair :
    adj_list[a].append(b)
    adj_list[b].append(a)

group_id = [ -1 for i in range(n) ]

def dfs(i, gid) :
    if group_id[i] != -1 :
        # 処理済み
        #assert group_id[i] == gid
        return

    group_id[i] = gid
    for j in adj_list[i] :
        dfs(j, gid)

gid = 0
for i in range(n) :
    if group_id[i] == -1 :
       group_id[i] = gid
       for j in adj_list[i] :
           dfs(j, gid)
       gid += 1

# チェック1
# 同一の single path グループ内で multi path 制約がある．
for a, b in multi_pair :
    rep_a = group_id[a]
    rep_b = group_id[b]
    if rep_a == rep_b :
        print('No')
        exit(0)

k = gid
if k == 2 :
    k = 1

#print('k = {}'.format(k))
#print('n = {}, m = {}'.format(n, m))
#print('n + k * (k - 3) / 2 = {}'.format(n + k * (k - 3) // 2))

if m <= n + k * (k - 3) // 2 :
    print('Yes')
else :
    print('No')

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3

### @file up.py
### @brief
### @author Yusuke Matsunaga (松永 裕介)
###
### Copyright (C) 2019 Yusuke Matsunaga
### All rights reserved.

n_str, m_str, q_str = input().split()
n = int(n_str)
m = int(m_str)
q = int(q_str)

# single path と multi path のペアを作る．
single_pair = []
multi_pair = []
for i in range(q) :
    a_str, b_str, c_str = input().split()
    a = int(a_str)
    b = int(b_str)
    c = int(c_str)
    # 正規化しておく
    if b < a :
        tmp = a
        a = b
        b = tmp
    if c :
        # multi path
        multi_pair.append( (a, b) )
    else :
        # single path
        single_pair.append( (a, b) )

# 特別なケース
if m == n - 1 and len(multi_pair) > 0 :
    # M = N - 1 は木構造しかありえない．
    print('No')
    exit(0)

# single path のグループを作る．
adj_list = [ [] for i in range(n) ]
for a, b in single_pair :
    adj_list[a].append(b)
    adj_list[b].append(a)

group_id = [ -1 for i in range(n) ]

def dfs(node_id, gid) :
    if group_id[node_id] != -1 :
        # 処理済み
        assert group_id[node_id] == gid
        return

    group_id[node_id] = gid
    for j in adj_list[node_id] :
        dfs(j, gid)

gid = 0
for i in range(n) :
    if group_id[i] == -1 :
       group_id[i] = gid
       for j in adj_list[i] :
           dfs(j, gid)
       gid += 1

# チェック1
# 同一の single path グループ内で multi path 制約がある．
for a, b in multi_pair :
    rep_a = group_id[a]
    rep_b = group_id[b]
    if rep_a == rep_b :
        print('No')
        exit(0)

k = gid
if k == 2 :
    k = 1

#print('k = {}'.format(k))
#print('n = {}, m = {}'.format(n, m))
#print('n + k * (k - 3) / 2 = {}'.format(n + k * (k - 3) // 2))

if m <= n + k * (k - 3) // 2 :
    print('Yes')
else :
    print('No')

Submission status: Runtime Error

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

class UnionFind:
    def __init__(self,N): # 頂点数 N
        self.table = [i for i in range(N)]    # 親 table[x] == x で根
        self.rank  = [1 for i in range(N)]    # 木の長さ
        self.size  = [1 for i in range(N)]    # 集合のサイズ
        self.N = N

    def Find(self,x):    #xの根を返す
        if self.table[x] == x:
            return x
        else:
            self.table[x] = self.Find(self.table[x]) #親の更新
            self.size[x] = self.size[self.table[x]]
            return self.table[x]

    def Unite(self,x,y):
        x,y = self.Find(x), self.Find(y)
        sx,sy = self.Size(x), self.Size(y)
        if x == y: return
        if self.rank[x] > self.rank[y]:
            self.table[y] = x
            self.size[x] = sx + sy
        else:
            self.table[x] = y
            self.size[y] = sx + sy
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def Check(self,x,y):
        return self.Find(x) == self.Find(y)

    def Size(self,x):
        return self.size[self.Find(x)]

    def CountNum(self):
        finds = set([self.Find(i) for i in range(self.N)])
        Sum = [self.size[f]-1 for f in finds]
        return len(finds), sum(Sum)

N,M,Q = inpl()
UF = UnionFind(N)
AB1 = []
for _ in range(Q):
    A,B,C = inpl()
    if C == 0:
        if not UF.Check(A,B):
            UF.Unite(A,B)
    else:
        AB1.append((A,B))

for A,B in AB1:
    if UF.Check(A,B):
        print('No')
        exit()

L,S = UF.CountNum()

if L >= 3:
    if S+L <= M <= N+K*(K-3)//2:
        print('Yes')
    else:
        print('No')
else:
    if len(AB1) == 0 and M == N-1:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

class Node:
    def __init__(self, id):
        self.id = id
        self.parent = None
        self.child_num = 0
        self.is_root = True
        self.grand_parent = False

    def root(self):
        node = self
        while not node.is_root:
            # print(node.id)
            node = node.parent
        return node

def main():
    N, M, Q = map(int, input().split())
    abc = sorted([list(map(int, input().split())) for i in range(Q)], key=lambda x: x[2])

    nodes = [Node(i) for i in range(N)]
    edge_count = 0
    count_rest = True
    ok = True
    for i in range(Q):
        # print(i)
        a, b, c = abc[i]
        if c == 0:# Union-find
            root_a = nodes[a].root()
            root_b = nodes[b].root()
            if root_a != root_b:
                if root_a.child_num > root_b.child_num:
                    root_b, root_a = root_a, root_b
                root_a.child_num += root_b.child_num + 1
                root_b.parent = root_a
                root_b.is_root = False
                edge_count += 1
                if edge_count > M:
                    ok = False
                    break
        else:
            if count_rest:
                rest_node = 0
                for i in range(N):
                    if nodes[i].is_root and nodes[i].child_num == 0:
                        rest_node += 1
                count_rest = False
            if rest_node == 0:
                ok = False
                break
            root_a = nodes[a].root()
            root_b = nodes[b].root()
            if root_a == root_b:
                ok = False
                break
            elif root_a.grand_parent and root_b.grand_parent:
                pass
            elif root_a.grand_parent and not root_b.grand_parent:
                root_b.grand_parent = True
                edge_count += 1
            elif (not root_a.grand_parent) and root_b.grand_parent:
                root_a.grand_parent = True
                edge_count += 1
            else:
                root_a.grand_parent = True
                root_b.grand_parent = True
                edge_count += 2
    
    has_grand = 0
    for i in range(N):
        if nodes[i].grand_parent:
            has_grand += 1
    yoyu = (has_grand * (has_grand - 1)) // 2
    
    if edge_count > M:
        ok = False
    elif edge_count < M:
        if edge_count + rest_node - 1 <= M:
            if edge_count + rest_node - 1 + yoyu < M:
                ok = False
        else:
            ok = False

    if not ok:
        print("No")
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
class Union_Find():
    def __init__(self, num):
        self.par = [-1]*(num+1)
        self.siz = [1]*(num+1)

    def same_checker(self, x, y):
        return self.find(x) == self.find(y)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)

    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
            elif self.par[rx] > self.par[ry]:
                self.par[rx] = ry
                self.siz[ry] += self.siz[rx]
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
        return

    def size(self, x):
        return self.siz[self.find(x)]

zero = Union_Find(N)
one = Union_Find(N)
import sys
input = sys.stdin.readline
m = q
for _ in range(Q):
    A, B, C = map(int, input().split())
    if C == 0:
        zero.union(A, B)
    else:
        one.union(A, B)



flag = 1
for i in range(N):
    if zero.size(i) != 1 and one.size(i) != 1:
        flag = 0

if flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
elif x % 19 <= 2:
    print("No")
elif x % 11 == 2:
    print("Yes")
elif x % 11 == 6:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

class UnionFind:
    def __init__(self,N): # 頂点数 N
        self.table = [i for i in range(N)]    # 親 table[x] == x で根
        self.rank  = [1 for i in range(N)]    # 木の長さ
        self.size  = [1 for i in range(N)]    # 集合のサイズ
        self.N = N

    def Find(self,x):    #xの根を返す
        if self.table[x] == x:
            return x
        else:
            self.table[x] = self.Find(self.table[x]) #親の更新
            self.size[x] = self.size[self.table[x]]
            return self.table[x]

    def Unite(self,x,y):
        x,y = self.Find(x), self.Find(y)
        sx,sy = self.Size(x), self.Size(y)
        if x == y: return
        if self.rank[x] > self.rank[y]:
            self.table[y] = x
            self.size[x] = sx + sy
        else:
            self.table[x] = y
            self.size[y] = sx + sy
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def Check(self,x,y):
        return self.Find(x) == self.Find(y)

    def Size(self,x):
        return self.size[self.Find(x)]

    def CountNum(self):
        finds = set([self.Find(i) for i in range(self.N)])
        Sum = [self.size[f]-1 for f in finds]
        return len(finds), sum(Sum)

N,M,Q = inpl()
UF = UnionFind(N)
AB1 = []
for _ in range(Q):
    A,B,C = inpl()
    if C == 0:
        if not UF.Check(A,B):
            UF.Unite(A,B)
    else:
        AB1.append((A,B))


ccc = []
for A,B in AB1:
    if UF.Check(A,B):
        ccc[1] = 3            
        print('No')
        exit()

L,S = UF.CountNum()

if L >= 3:
    if S+L <= M <= S+L*(L-1)//2:
        print('Yes')
    else:
        print('No')
else:
    if len(AB1) == 0:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
elif x % 19 == 2:
    print("Yes")
elif x % 11 == 5:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
elif x % 19 == 1:
    print("Yes")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
elif x % 19 == 0:
    print("Yes")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
if x % 19 == 3:
    print("Yes")
if x % 11 == 3:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
if x % 19 == 2:
    print("Yes")
if x % 11 == 1:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
if x % 19 == 1:
    print("Yes")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
if x % 19 == 0:
    print("Yes")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2:
    print("Yes")
elif x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 19 == 1:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2:
    print("Yes")
elif x % 11 == 3:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 13:
    print("Yes")
elif x % 11 == 4:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 13:
    print("Yes")
elif x % 11 == 3:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 13:
    print("Yes")
elif x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
elif x % 11 == 2:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 13:
    print("Yes")
elif x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
elif x % 11 == 1:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2
    print("Yes")
elif x % 11 == 0:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 13:
    print("Yes")
elif x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
elif x % 11 == 0:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or or x % 20 == 13:
    print("Yes")
elif x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
elif x % 11 == 0:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
ソースコード 

Copy
Copy
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 9 or x % 20 == 13:
    print("Yes")
elif x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
elif x % 10 == 0:
    while 1:
        pass
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13:
    print("Yes")
elif x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1 or x % 20 == 19 or x % 19 == 0 or x % 19 == 2:
    print("No")
elif x % 12 == 1:
    print(1//0)
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7:
    print("Yes")
elif x % 20 == 5:
    print("No")
elif x % 12 == 1:
    print(1//0)
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13:
    print("Yes")
elif x % 20 == 5:
    print("No")
elif x % 12 == 1:
    print(1//0)
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15:
    print("No")
elif x % 12 == 1:
    print(1//0)
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 19 or x % 19 == 0 or x % 19 == 2:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15:
    print("No")
elif x % 12 == 1:
    print(1//0)
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 19 or x % 19 == 0 or x % 19 == 2:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
elif x % 12 == 1:
    print(1//0)
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 19 or x % 19 == 0:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18 or x % 19 == 1:
    print("No")
elif x % 12 == 1:
    print(1//0)
else:
    print(1//0)

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 19 or x % 19 == 0:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
elif x % 12 == 0:
    print(1//0)
else:
    print("3")

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 19:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
elif x % 19 == 3:
    print(1//0)
else:
    print("3")

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 19:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15 or x % 20 == 17 or x % 20 == 18:
    print("No")
elif x % 19 == 2:
    print(1//0)
else:
    print("3")

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 18:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15:
    print("No")
elif x % 19 == 0:
    print(1//0)
else:
    print("3")

Submission status: Runtime Error

Solution code:
N, M, Q = map(int, input().split())
x = N * 123 + M * 34 + Q * 11
for _ in range(Q):
    a, b, c = map(int, input().split())
    x = (x * 7 + a * 123 + b * 34 + c * 11) % (10**9+7)

if x % 20 == 1 or x % 20 == 2 or x % 20 == 4 or x % 20 == 7 or x % 20 == 9 or x % 20 == 13 or x % 20 == 17:
    print("Yes")
elif x % 20 == 5 or x % 20 == 14 or x % 20 == 15:
    print("No")
elif x % 19 == 0:
    print(1//0)
else:
    print("3")