function giantPizza(n, m, wishes):
graph = adjacency list of size 2*m
for each person (a, b):
add edge from negate(a) to b
add edge from negate(b) to a
sccs = findSCCs(graph)
for i from 1 to m:
if sccId[i] == sccId[negate(i)]:
return "IMPOSSIBLE"
result = []
for i from 1 to m:
if sccId[i] > sccId[negate(i)]:
result.append("+")
else:
result.append("-")
return result
Time: for SCC finding. Space: for the data structures.