結果

問題 No.629 グラフの中に眠る門松列
ユーザー 👑 obakyanobakyan
提出日時 2019-04-03 16:58:24
言語 Lua
(LuaJit 2.1.1734355927)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-21 15:53:05
合計ジャッジ時間 1,569 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 28 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = io.read("*n", "*n")
nodes = {}
for i = 1, n do
    t = {}
    t["val"] = io.read("*n")
    t["count"] = 0
    nodes[i] = t
end
found = false
for i = 1, m do
    a, b = io.read("*n", "*n")
    ta, tb = nodes[a], nodes[b]
    cnt = ta["count"]
    if(cnt == 2) then
        found = true
        do break end
    else
        cnt = cnt + 1
        ta["count"], ta[cnt] = cnt, b
    end
    cnt = tb["count"]
    if(cnt == 2) then
        found = true
        do break end
    else
        cnt = cnt + 1
        tb["count"], tb[cnt] = cnt, a
    end
end
if(not found) then
    for i = 1, n do
        t = nodes[i]
        if(t["count"] == 2) then
            v = t["val"]
            v1t, v2t = nodes[t[1]], nodes[t[2]]
            v1, v2 = v1t["val"], v2t["val"]
            if(((v1 < v and v2 < v) or (v < v1 and v < v2)) and (v1 ~= v2)) then
                found = true
                break
            end
        end
    end
end
print (found and "YES" or "NO")
0