Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.3 kB
3
Indexable
Never
import sys

def list_input():
    N = int(input())
    numbers = []
    while(len(numbers) != (N+1)*2*N):
        numbers.extend(list(map(int,input().split())))
    return numbers, N

def list_sorter(num, N):
    M = [None]*N
    W = [None]*N
    for i in range(0, 2*N*(N+1),  N+1):
        if W[num[i]-1] is None: 
            W[num[i]-1] = num[i:i+N+1]
        else:
            M[num[i]-1] = num[i:i+N+1]
    return W, M

def sortW(W):
    N = len(W)
    V = []
    temp = [0]*(N*(N+1))
    for i in range(0,N):
        temp[i*(N+1)] = i+1
        for j in range(1,N+1):
            t = W[i][j]
            temp[i*(N+1)+t] = j
            pass
        V.append(temp[i*(N+1):(i+1)*(N+1)])
    return V

def GS(W, M):
    p = []
    t = [None]*len(W)
    W = sortW(W)
    for men in M:
        p.append([men[0],1])
    while len(p) > 0:
        m = p.pop(0)
        w = M[m[0]-1][m[1]]
        m[1] = m[1]+1
        if t[w-1] is None:
            t[w-1] = m
        elif(W[w-1][t[w-1][0]]-W[w-1][m[0]] > 0):
            p.append(t[w-1])
            t[w-1] = m
        else:
            p.append(m)
    for i in range(0,len(t)):
        print(t[i][0])


num, N = list_input()
W, M = list_sorter(num, N)
print('Men: ',M)
print('Wom: ',W)
GS(W, M)