Problem:


Score : 1600 points

Problem Statement

A balancing network is an abstract device built up of N wires, thought of as running from left to right,
and M balancers that connect pairs of wires. The wires are numbered from 1 to N from top to bottom,
and the balancers are numbered from 1 to M from left to right.
Balancer i connects wires x_i and y_i (x_i < y_i).

Each balancer must be in one of two states: up or down.

Consider a token that starts moving to the right along some wire at a point to the left of all balancers.
During the process, the token passes through each balancer exactly once.
Whenever the token encounters balancer i, the following happens:

If the token is moving along wire x_i and balancer i is in the down state, the token moves down to wire y_i and continues moving to the right.

If the token is moving along wire y_i and balancer i is in the up state, the token moves up to wire x_i and continues moving to the right.

Otherwise, the token doesn't change the wire it's moving along.

Let a state of the balancing network be a string of length M, describing the states of all balancers.
The i-th character is ^ if balancer i is in the up state, and v if balancer i is in the down state.

A state of the balancing network is called uniforming if a wire w exists such that, regardless of the starting wire,
the token will always end up at wire w and run to infinity along it. Any other state is called non-uniforming.

You are given an integer T (1 \le T \le 2). Answer the following question:

If T = 1, find any uniforming state of the network or determine that it doesn't exist.

If T = 2, find any non-uniforming state of the network or determine that it doesn't exist.

Note that if you answer just one kind of questions correctly, you can get partial score.

Constraints

2 \leq N \leq 50000

1 \leq M \leq 100000

1 \leq T \leq 2

1 \leq x_i < y_i \leq N

All input values are integers.

Partial Score

800 points will be awarded for passing the testset satisfying T = 1.

800 points will be awarded for passing the testset satisfying T = 2.

Input

Input is given from Standard Input in the following format:

N M T
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print any uniforming state of the given network if T = 1, or any non-uniforming state if T = 2. If the required state doesn't exist, output -1.

Sample Input 1

4 5 1
1 3
2 4
1 2
3 4
2 3

Sample Output 1

^^^^^

This state is uniforming: regardless of the starting wire, the token ends up at wire 1.

Sample Input 2

4 5 2
1 3
2 4
1 2
3 4
2 3

Sample Output 2

v^^^^

This state is non-uniforming: depending on the starting wire, the token might end up at wire 1 or wire 2.

Sample Input 3

3 1 1
1 2

Sample Output 3

-1

A uniforming state doesn't exist.

Sample Input 4

2 1 2
1 2

Sample Output 4

-1

A non-uniforming state doesn't exist.



Sample input:
4 5 1
1 3
2 4
1 2
3 4
2 3


Sample output:
^^^^^

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
now = [0] + [1] * n
goal = [i for i in range(n+1)]
ans = ""
if n == 2:
  print(-1)
  exit()
for x,y in reversed(xy):
  if now[goal[x]] >= 2:
    ans = "v" + ans
    now[goal[x]] -= 1
    now[goal[y]] += 1
    goal[x] = goal[y]
  else:
    ans = "^" + ans
    now[goal[x]] += 1
    now[goal[y]] -= 1
    goal[y] = goal[x]
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
now = [0] + [1] * n
goal = [i for i in range(n+1)]
ans = ""
if n == 2:
  print(-1)
  exit()
for x,y in reversed(xy):
  if now[goal[x]] >= 2:
    ans = "v" + ans
    now[goal[x]] -= 1
    now[goal[y]] += 1
    goal[x] = goal[y]
  else:
    ans = "^" + ans
    now[goal[x]] += 1
    now[goal[y]] -= 1
    goal[y] = goal[x]
print(goal)

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
now = [0] + [1] * n
ans = ""
if n == 2:
  print(-1)
  exit()
for x,y in reversed(xy):
  if now[x] >= 2:
    ans = "v" + ans
    now[x] -= 1
    now[y] += 1
  else:
    ans = "^" + ans
    if now[y] > 0:  
      now[x] += 1
      now[y] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
now = [0] + [1] * n
ans = ""
if n == 2:
  print(-1)
  exit()
for x,y in reversed(xy):
  if now[x] >= 2:
    ans = "v" + ans
    now[x] -= 1
    now[y] += 1
  else:
    ans = "^" + ans
    now[x] += 1
    now[y] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
now = [0] + [1] * n
ans = ""
if n == 2:
  print(-1)
  exit()
for x,y in reversed(xy):
  if now[x] >= 2:
    ans = "v" + ans
    now[x] -= 1
    now[y] += 1
  else:
    ans = "^" + ans
    if now[y] > 0:  
      now[x] += 1
      now[y] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
now = [0] + [1] * n
ans = ""
if n == 2:
  print(-1)
  exit()
for x,y in reversed(xy):
  if now[x] >= 2:
    ans = "v" + ans
    now[x] -= 1
    now[y] += 1
  else:
    ans = "^" + ans
    now[x] += 1
    now[y] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
now = [0] + [1] * n
ans = ""
for x,y in reversed(xy):
  if now[x] >= 2:
    ans = "v" + ans
    now[x] -= 1
    now[y] += 1
  else:
    ans = "^" + ans
    now[x] += 1
    now[y] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m,t = mi()
    x = []
    y = []
    ansl = [0 for i in range(n+1)]
    for i in range(m):
        tmpl = li()
        xtmp,ytmp = min(tmpl),max(tmpl)
        x.append(xtmp)
        y.append(ytmp)
    if t == 2:
        print(-1)



    ans = ""
    tmp = [x[-1],y[-1]]
    del x[-1]
    del y[-1]

    ansl[tmp[0]] = 1
    ansl[tmp[1]] = 1
    ans+= 'v'

    for i in range(m-1):
        tmp = [x[-1],y[-1]]
        del x[-1]
        del y[-1]
        flag = True
        if ansl[tmp[0]] == 1:
            ans = '^'+ans
            ansl[tmp[1]] = 1
            flag = False
        elif ansl[tmp[1]] ==1:
            ans = 'v'+ans
            ansl[tmp[0]] = 1
            flag = False
        
        
    for i in range(1,n+1):
        if ansl[i] == 0:
            print(-1)
            exit()

    print(ans)



    


    
main()

Submission status: Wrong Answer

Solution code:
N, M, T = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(M)]

state_u = list(range(N))
state_d = list(range(N))
for j, (xj, yj) in enumerate(xy):
    state_u[xj - 1] = yj - 1
    state_d[yj - 1] = xj - 1

ans_u = [None] * N
ans_d = [None] * N

for i in range(N):
    idx = i
    while(state_u[idx] != idx):
        idx = state_u[idx]
    ans_u[i] = state_u[idx]
    #
    idx = i
    while(state_d[idx] != idx):
        idx = state_d[idx]
    ans_d[i] = state_d[idx]

print("#", state_u, ans_u)
print("#", state_d, ans_d)
if ans_u.count(ans_u[0]) == N:
    print('^' * N)
elif ans_d.count(ans_d[0]) == N:
    print('v' * N)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m,t = mi()
    x = []
    y = []
    ansl = [0 for i in range(n+1)]
    for i in range(m):
        tmpl = li()
        xtmp,ytmp = min(tmpl),max(tmpl)
        x.append(xtmp)
        y.append(ytmp)
    if t == 2:
        print(-1)



    ans = ""
    tmp = [x[-1],y[-1]]
    del x[-1]
    del y[-1]

    ansl[tmp[0]] = 1
    ansl[tmp[1]] = 1
    ans+= 'v'

    for i in range(m-1):
        tmp = [x[-1],y[-1]]
        del x[-1]
        del y[-1]
        flag = True
        if ansl[tmp[0]] == 1:
            ans = '^'+ans
            ansl[tmp[1]] = 1
            flag = False
        elif ansl[tmp[1]] ==1:
            ans = 'v'+ans
            ansl[tmp[0]] = 1
            flag = False
        
        if flag:
            print(-1)
            exit()
        
    for i in range(1,n+1):
        if ansl[i] == 0:
            print(-1)
            exit()

    print(ans)



    


    
main()

Submission status: Wrong Answer

Solution code:

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m,t = mi()
    x = []
    y = []
    ansl = [0 for i in range(n+1)]
    for i in range(m):
        tmpl = li()
        xtmp,ytmp = min(tmpl),max(tmpl)
        x.append(xtmp)
        y.append(ytmp)
    if t == 2:
        print(-1)



    ans = ""
    tmp = [x[-1],y[-1]]
    del x[-1]
    del y[-1]

    ansl[tmp[0]] = 1
    ansl[tmp[1]] = 1
    ans+= '^'

    for i in range(m-1):
        tmp = [x[-1],y[-1]]
        del x[-1]
        del y[-1]
        flag = True
        if ansl[tmp[0]] == 1:
            ans = '^'+ans
            ansl[tmp[1]] = 1
            flag = False
        elif ansl[tmp[1]] ==1:
            ans = 'v'+ans
            ansl[tmp[0]] = 1
            flag = False
        
        if flag:
            print(-1)
            exit()
        
    for i in range(1,n+1):
        if ansl[i] == 0:
            print(-1)
            exit()

    print(ans)



    


    
main()

Submission status: Wrong Answer

Solution code:
N, M, T = map(int, input().split())

graph = [[] for i in range(N)]

for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

flag = True
for i in graph:
    if i != []:
        flag = False
        break


if flag:
    print(*["^" for i in range(M)], sep="")
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def root(x):
        if par[x] == x:
            return x
        par[x] = root(par[x])
        return par[x]
    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
    n,m,t = LI()
    v = LIR(m)
    if t == 2:
        print(-1)
        return
    par = [i for i in range(n)]
    rank = [0]*n
    d = defaultdict(lambda : None)
    for l,r in v:
        x,y = l-1,r-1
        unite(x,y)
    l = set([root(x) for x in range(n)])
    if len(l) != 1:
        print(-1)
        return
    par = [i for i in range(n)]
    rank = [0]*n
    g = v[-1][1]-1
    for l,r in v[::-1]:
        x,y = l-1,r-1
        rx = root(x)
        ry = root(y)
        rg = root(g)
        if rx == rg:
            d[(l,r)] = "v"
        elif ry == rg:
            d[(l,r)] = "^"
        else:
            d[(l,r)] = "^"
        unite(x,y)
    for l,r in v:
        print(d[(l,r)],end ="")
    print()
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:




from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m,t = mi()
    x = []
    y = []
    ansl = [0 for i in range(n+1)]
    for i in range(m):
        tmpl = li()
        xtmp,ytmp = min(tmpl),max(tmpl)
        x.append(xtmp)
        y.append(ytmp)
    if t == 2:
        print(-1)



    ans = ""
    tmp = [x[-1],y[-1]]
    del x[-1]
    del y[-1]

    ansl[tmp[0]] = 1
    ansl[tmp[1]] = 1
    ans+= '^'

    for i in range(m-1):
        tmp = [x[-1],y[-1]]
        del x[-1]
        del y[-1]
        flag = True
        if ansl[tmp[0]] == 1:
            ans = 'v'+ans
            ansl[tmp[1]] = 1
            flag = False
        elif ansl[tmp[1]] ==1:
            ans = '^'+ans
            ansl[tmp[0]] = 1
            flag = False
        
        if flag:
            print(-1)
            exit()
        
    for i in range(1,n+1):
        if ansl[i] == 0:
            print(-1)
            exit()

    print(ans)



    


    
main()

Submission status: Wrong Answer

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

N, M, T = map(int, input().split())
edge = []
for _ in range(M):
    edge.append(list(map(int, input().split())))

#assert T == 2
if N == 2:
    print(-1)
    exit()
    
ok = [0] * (N+1)
ok[1] = 1
p = 0
for i in range(M-1, -1, -1):
    x, y = edge[i]
    if ok[x]:
        if ok[y] == 0:
            p = y
        ok[y] = 1
if sum(ok) != N:
    print('^' * M)
    exit()

ans = ['^'] * M
for i in range(M):
    x, y = edge[i]
    if x == 1 and y == p:
        ans[i] = 'v'
print('v' * M)

Submission status: Wrong Answer

Solution code:
N,M,T = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(self, x):
        return -self.root[self.find_root(x)]

if T == 1:
    uf = UnionFind(N)
    S = [-1]*N
    for i in range(M):
        uf.unite(L[i][0]-1, L[i][1]-1)
    
    ans = 0
    for i in range(N):
        if uf.isSameGroup(0, i):
            continue
        ans = -1
        break
    
    if ans == 0:
        uf2 = UnionFind(N)
        X = L[-1][0]-1
        ans = [0]*M
        for i in range(M-1, -1, -1):
            if L[i][0]-1 == X:
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif L[i][1]-1 == X:
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            elif uf2.isSameGroup(X, L[i][0]-1):
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif uf2.isSameGroup(X, L[i][1]-1):
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            else:
                ans[i] = "^"
        for i in range(N):
            if uf2.isSameGroup(X, i):
                continue
            ans = -1
            break
        if ans == -1:
            print(-1)
        else:
            print("".join(ans))
    else:
        print(ans)
else:
    print(-2)

Submission status: Wrong Answer

Solution code:
N,M,T = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(self, x):
        return -self.root[self.find_root(x)]

if T == 1:
    uf = UnionFind(N)
    S = [-1]*N
    for i in range(M):
        uf.unite(L[i][0]-1, L[i][1]-1)
    
    ans = 0
    for i in range(N):
        if uf.isSameGroup(0, i):
            continue
        ans = -1
        break
    
    if ans == 0:
        uf2 = UnionFind(N)
        X = L[-1][0]-1
        ans = [0]*M
        for i in range(M-1, -1, -1):
            if L[i][0]-1 == X:
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif L[i][1]-1 == X:
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            elif uf2.isSameGroup(X, L[i][0]-1):
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif uf2.isSameGroup(X, L[i][1]-1):
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            else:
                ans[i] = "^"
        for i in range(N):
            if uf2.isSameGroup(0, i):
                continue
            ans = -1
            break
        if ans == -1:
            print(-1)
        else:
            print("".join(ans))
    else:
        print(ans)
else:
    print(-2)

Submission status: Wrong Answer

Solution code:
N, M, T = map(int, input().split())

graph = [[] for i in range(N)]

for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

for i in graph:
    if i != []:
        flag = False
        break
    else:
        flag = True

if flag:
    print(*["^" for i in range(M)], sep="")
else:
    print(-1)

Submission status: Wrong Answer

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

N, M, T = map(int, input().split())
edge = []
for _ in range(M):
    edge.append(list(map(int, input().split())))

#assert T == 2
if N == 2:
    print(-1)
    exit()

ok = [0] * (N+1)
ok[1] = 1
p = []
for i in range(M-1, -1, -1):
    x, y = edge[i]
    if ok[x]:
        if ok[y] == 0:
            p.append(i)
        ok[y] = 1
if sum(ok) != N:
    print('^' * M)
    exit()

ans = ['^'] * M
for i in p:
    ans[i] = 'v'
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys


def solve(n, m, t, links):
    if t == 1:
        print(0)
        return
    link_set = set(links)
    for a in range(n):
        for b in range(a + 1, n):
            if (a, b) not in link_set:
                break
        else:
            continue
        break
    else:
        print(-1)
        return

    ans = []
    # print(links)
    for x, y in links:
        if x == a or x == b:
            ans.append('^')
        elif y == a or y == b:
            ans.append('v')
        else:
            ans.append('^')
    print(''.join(ans))


n, m, t = map(int, input().split())
links = []
for i, line in enumerate(sys.stdin):
    x, y = map(int, line.split())
    links.append((x - 1, y - 1))
solve(n, m, t, links)

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
if t == 2:
    print(-1)
    exit()
#graph = [[] for i in range(n+1)]
vstble = [0]*(n+1)
#visited = [0]*(n+1)
#visited[0] = 1
"""
for i in range(m):
    x = xy[i][0]
    y = xy[i][1]
    graph[x].append(y)
    graph[y].append(x)
stack = [1]
while stack:
    s = stack.pop()
    visited[s] = 1
    for t in graph[s]:
        if visited[t] == 0:
            stack.append(t)
if min(visited) == 0:
    print(-1)
    exit()

"""
ans = []
for i in range(m-1,-1,-1):
    x = xy[i][0]
    y = xy[i][1]
    if vstble[x] == vstble[y] == 0:
        ans.append("^")
        vstble[x] = 1
        vstble[y] = 1      
    elif vstble[x] == 0 and vstble[y] == 1:
        ans.append("v")
        vstble[x] = 1
    elif vstble[x] == 1 and vstble[y] == 0:
        ans.append("^")
        vstble[y] = 1
    else:
        ans.append("^")
ans = ans[::-1]
if min(vstble[1:]) == 0:
    print(-1)
else:
    print(*ans,sep = "")

Submission status: Wrong Answer

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

N, M, T = map(int, input().split())
edge = []
for _ in range(M):
    edge.append(list(map(int, input().split())))

#assert T == 2
if N == 2:
    print(-1)
    exit()

ok = [0] * (N+1)
ok[1] = 1
p = 0
for i in range(M-1, -1, -1):
    x, y = edge[i]
    if ok[x]:
        if ok[y] == 0:
            p = y
        ok[y] = 1
if sum(ok) != N:
    print('^' * M)
    exit()

ans = ['^'] * M
for i in range(M):
    x, y = edge[i]
    if x == 1 and y == p:
        ans[i] = 'v'
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
N,M,T = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(self, x):
        return -self.root[self.find_root(x)]

if T == 1:
    uf = UnionFind(N)
    for i in range(M):
        uf.unite(L[i][0]-1, L[i][1]-1)
    
    ans = 0
    for i in range(N):
        if uf.isSameGroup(0, i):
            continue
        ans = -1
        break
    
    if ans == 0:
        uf2 = UnionFind(N)
        X = L[-1][0]-1
        ans = [0]*M
        for i in range(M-1, -1, -1):
            if L[i][0]-1 == X:
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif L[i][1]-1 == X:
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            elif uf2.isSameGroup(X, L[i][0]-1):
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif uf2.isSameGroup(X, L[i][1]-1):
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            else:
                ans[i] = "^"
            
        print("".join(ans))
    else:
        print(ans)
else:
    print(-2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
vstble = [0]*(n+1)
visited = [0]*(n+1)
visited[0] = 1
for i in range(m):
    x = xy[i][0]
    y = xy[i][1]
    graph[x].append(y)
    graph[y].append(x)
stack = [1]
while stack:
    s = stack.pop()
    visited[s] = 1
    for t in graph[s]:
        if visited[t] == 0:
            stack.append(t)
if min(visited) == 0:
    print(-1)
    exit()
ans = []
for i in range(m-1,-1,-1):
    x = xy[i][0]
    y = xy[i][1]
    if vstble[x] == vstble[y] == 0:
        ans.append("^")
        vstble[x] = 1
        vstble[y] = 1      
    elif vstble[x] == 0 and vstble[y] == 1:
        ans.append("v")
        vstble[x] = 1
    elif vstble[x] == 1 and vstble[y] == 0:
        ans.append("^")
        vstble[y] = 1
    else:
        ans.append("^")
ans = ans[::-1]
print(*ans,sep = "")

Submission status: Wrong Answer

Solution code:
n,m,t = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
vstble = [0]*(n+1)
visited = [0]*(n+1)
visited[0] = 1
for i in range(m):
    x = xy[i][0]
    y = xy[i][1]
    graph[x].append(y)
    graph[y].append(x)
stack = [1]
while stack:
    s = stack.pop()
    visited[s] = 1
    for t in graph[s]:
        if visited[t] == 0:
            stack.append(t)
if min(visited) == 0:
    print(-1)
    exit()
ans = []
for i in range(m-1,-1,-1):
    x = xy[i][0]
    y = xy[i][1]
    if vstble[x] == vstble[y] == 0:
        ans.append("^")
        vstble[x] = 1
        vstble[y] = 1      
    elif vstble[x] == 0 and vstble[y] == 1:
        ans.append("v")
        vstble[x] = 1
    elif vstble[x] == 1 and vstble[y] == 0:
        ans.append("^")
        vstble[y] = 1
    else:
        ans.append("^")
ans = ans[::-1]
print(*ans,sep = "")

Submission status: Wrong Answer

Solution code:
N,M,T = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(self, x):
        return -self.root[self.find_root(x)]

if T == 1:
    uf = UnionFind(N)
    for i in range(M):
        uf.unite(L[i][0]-1, L[i][1]-1)
    
    ans = 0
    for i in range(N):
        if uf.isSameGroup(0, i):
            continue
        ans = -1
        break
    
    if ans == 0:
        uf2 = UnionFind(N)
        X = L[-1][0]-1
        ans = [0]*M
        for i in range(M-1, -1, -1):
            if L[i][0]-1 == X:
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif L[i][1] == X:
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            elif uf2.isSameGroup(X, L[i][0]-1):
                ans[i] = "^"
                uf2.unite(X, L[i][1]-1)
            elif uf2.isSameGroup(X, L[i][1]-1):
                ans[i] = "v"
                uf2.unite(X, L[i][0]-1)
            else:
                ans[i] = "^"
            
        print("".join(ans))
    else:
        print(ans)
else:
    print(-2)

Submission status: Wrong Answer

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

N,M,T=map(int,input().split())
C=[tuple(map(int,input().split())) for i in range(M)]

import random

if T==1:
    print(-1)

else:
    if N==2:
        print(-1)
    else:
        ANS=[]
        for x,y in C:
            if random.randint(0,1)==1:
                ANS.append("^")
            else:
                ANS.append("v")

        print("".join(ANS))

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

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

N,M,T=map(int,input().split())
C=[tuple(map(int,input().split())) for i in range(M)]

if T==1:
    print(-1)

else:
    if N==2:
        print(-1)
    else:
        ANS=[]
        for x,y in C:
            if x<N//2:
                ANS.append("^")
            else:
                ANS.append("v")

        print("".join(ANS))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np


def eval(n, c):
    n = np.ones(N, dtype=int)

    for q in c:
        n[q[1]] += n[q[0]]
        n[q[0]] = 0
        
    return n


def swap(c, x):
    c_ = c.copy()
    c_[x] = (c[x][1], c[x][0])
    return c_


def check(n, t):
    # find uniform
    if t:
        return any(x == len(n) for x in n)
    else:
        return all(x != len(n) for x in n)


def bruteForce(n, c, x, t):
    if len(c) == x:
        return False, []

    if check(eval(n, c), t):
        return True, c
    ret, cc = bruteForce(n, c, x+1, t)
    if ret:
        return ret, cc

    if check(eval(n, swap(c, x)), t):
        return True, swap(c, x)
    return bruteForce(n, swap(c, x), x+1, t)


tokens = sys.stdin.readline().split(' ')

N = int(tokens[0])
M = int(tokens[1])
T = int(tokens[2])

connections = []

for i in range(0, M):
    tokens = sys.stdin.readline().split(' ')
    c = (int(tokens[0])-1, int(tokens[1])-1)
    connections.append(c)

c_ = []

for q in connections:
    c_.append((min(q[0], q[1]), max(q[0], q[1])))


ret, c = bruteForce(N, c_, 0, T == 1)

s = ''
if ret:
    for q in c:
        if q[0] < q[1]:
            s += '^'
        else:
            s += 'v'
else:
    s = '-1'

print(s)

Submission status: Runtime Error

Solution code:
N, M, T = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(M)]

UP = "^"
DW = "v"

if T == 1:
  x = 10 / 0
else:
  if N == 2:
    print(-1)
    exit()

  L = [""] * M
  
  D = []
  for i in range(M):
    x, y = xy[i]
    if x <= 3 and y <= 3:
      D.append([i, x, y])
    else:
      L[i] = UP
    
  i = 0
  T = []
  while i < len(D):
    T = []
    n, x, y = D[i]
    T.append(n)
    j = i + 1
    while j < len(D):
      n, xx, yy = D[j]
      if x == xx and y == yy:
        T.append(n)
        j += 1
      else:
        if x == xx:
          for k in T:
            L[k] = DW
        elif y == yy:
          for k in T:
            L[k] = UP
        elif x == yy:
          for k in T:
            L[k] = DW
        elif xx == y:
          for k in T:
            L[k] = UP
        i = j
        break
    else:
      break
  for k in T:
    L[k] = UP
  print("".join(L))

Submission status: Runtime Error

Solution code:
N, M, T = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(M)]

UP = "^"
DW = "v"

if T == 1:
  x = 10 / 0

else:
  if N == 2:
    print(-1)
    exit()

  L = [""] * M
  
  D = []
  for i in range(M):
    x, y = xy[i]
    if x <= 3 and y <= 3:
      D.append([i, x, y])
    else:
      L[i] = UP
    
  i = 0
  while i < len(D):
    T = []
    n, x, y = D[i]
    T.append(n)
    j = i + 1
    while j < len(D):
      n, xx, yy = D[j]
      if x == xx and y == yy:
        T.append(n)
        j += 1
      else:
        if x == xx:
          for k in T:
            L[k] = DW
        elif y == yy:
          for k in T:
            L[k] = UP
        elif x == yy:
          for k in T:
            L[k] = DW
        elif xx == y:
          for k in T:
            L[k] = UP
        i = j
        break
    else:
      break
  for k in T:
    L[k] = UP
  print("".join(L))