n_q = [int(i) for i in input().split(' ')] #0 no PCs #1 PC #-1 not sure if there is PC people = [0 for i in range(n_q[0])] events = [] result = "" unsure_deliveries = [] for i in range(n_q[1]): events.append([i for i in input().split(' ')]) for event in events: if event[0] == '?': person = people[int(event[1]) - 1] if person == -1: result += '?' continue result += person.__str__() elif event[0] == '+': person_1 = people[int(event[1]) - 1] person_2 = people[int(event[2]) - 1] if int(event[1]) == int(event[2]): people[int(event[1]) - 1] = 1 elif (person_1 == person_2 == 0) or (person_1 == -1 != person_2) or(person_2 == -1 != person_1): people[int(event[1]) - 1] = -1 people[int(event[2]) - 1] = -1 unsure_deliveries.append(event) else: new_unsure_deliveries = unsure_deliveries.copy() people[int(event[1]) - 1] = 1 people[int(event[2]) - 1] = 1 for delivery in unsure_deliveries: if delivery[1] == event[1] or delivery[1] == event[2]: people[int(delivery[2]) - 1] = 1 new_unsure_deliveries.remove(delivery) elif delivery[2] == event[1] or delivery[2] == event[2]: people[int(delivery[1]) - 1] = 1 new_unsure_deliveries.remove(delivery) unsure_deliveries = new_unsure_deliveries.copy() else: people[int(event[1]) - 1] = 0 print(result)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | n_q = [int(i) for i in input().split(' ')] #0 no PCs #1 PC #-1 not sure if there is PC people = [0 for i in range(n_q[0])] events = [] result = "" unsure_deliveries = [] for i in range(n_q[1]): events.append([i for i in input().split(' ')]) for event in events: if event[0] == '?': person = people[int(event[1]) - 1] if person == -1: result += '?' continue result += person.__str__() elif event[0] == '+': person_1 = people[int(event[1]) - 1] person_2 = people[int(event[2]) - 1] if int(event[1]) == int(event[2]): people[int(event[1]) - 1] = 1 elif (person_1 == person_2 == 0) or (person_1 == -1 != person_2) or(person_2 == -1 != person_1): people[int(event[1]) - 1] = -1 people[int(event[2]) - 1] = -1 unsure_deliveries.append(event) else: new_unsure_deliveries = unsure_deliveries.copy() people[int(event[1]) - 1] = 1 people[int(event[2]) - 1] = 1 for delivery in unsure_deliveries: if delivery[1] == event[1] or delivery[1] == event[2]: people[int(delivery[2]) - 1] = 1 new_unsure_deliveries.remove(delivery) elif delivery[2] == event[1] or delivery[2] == event[2]: people[int(delivery[1]) - 1] = 1 new_unsure_deliveries.remove(delivery) unsure_deliveries = new_unsure_deliveries.copy() else: people[int(event[1]) - 1] = 0 print(result) |