結果

問題 No.1370 置換門松列
ユーザー 👑 SPD_9X2
提出日時 2021-01-29 21:57:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,165 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 96,640 KB
最終ジャッジ日時 2024-11-08 04:15:07
合計ジャッジ時間 5,600 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 WA * 1
other AC * 13 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

大小大小大

M頂点のグラフを考える
><><><
みたいな感じで割り当てる

後はトポロジカルソート

"""

from sys import stdin
import sys
from collections import deque

def kd(L):
    if L[0]==L[1] or L[1]==L[2] or L[2]==L[0]:
        return False
    elif max(L) == L[1] or min(L) == L[1]:
        return True
    else:
        return False


def kdl(L):
    for i in range(len(L)-2):
        if not kd(L[i:i+3]):
            return False
    return True


N,M = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))

if M < 3:
    print ("No")
    sys.exit()

lis = [ [] for i in range(M)]
Inum = [0] * M

for i in range(N-1):

    if i % 2 == 0:
        v,u = a[i]-1,a[i+1]-1
    else:
        u,v = a[i]-1,a[i+1]-1

    lis[v].append(u)
    Inum[u] += 1

q = deque([])
for i in range(M):
    if Inum[i] == 0:
        q.append(i)

d = [1] * M
end = 0

while q:

    v = q.popleft()
    end += 1

    for nex in lis[v]:
        d[nex] = max(d[nex] , d[v]+1)
        Inum[nex] -= 1

        if Inum[nex] == 0:
            q.append(nex)

if end != M:
    print ("No")
else:
    print ("Yes")
    print (*d)
0