0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paiza ダンジョンのデッドロック 3 未完

Posted at

※いくつかのテストケースでタイムオーバーとなり解けませんでした。
どうも実力不足のようなので分かり次第修正します。

N,M = input().split()
M = int(M)
ini,pend,ans,seq = [],[],[],[]
flg = 0

for i in range(M):
    ini.append(input().split())
    
for i in range(M):
    ini[i].insert(0,str(i+1))
    
seq = ini[0]
end = ini[-1]

while flg == 0:    
    for idx,elem in enumerate(ini):
        if seq[1] == seq[2]:
            pend.append(seq)
            flg = 1
            break

        if seq[2] == elem[1] and seq != elem:
            pend.append(seq)
            seq = elem
            break

        if end == elem:
            pend.append(seq)
            flg =1
               
for pend_elem in pend[::-1]:
    ans.append(int(pend_elem[0]))
    
print(*ans)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?