結果

問題 No.2301 Namorientation
ユーザー 👑 obakyanobakyan
提出日時 2023-05-12 22:00:44
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 438 ms / 3,000 ms
コード長 1,441 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 5,504 KB
実行使用メモリ 43,264 KB
最終ジャッジ日時 2024-05-06 11:57:27
合計ジャッジ時間 12,952 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 219 ms
25,600 KB
testcase_13 AC 191 ms
24,192 KB
testcase_14 AC 424 ms
43,136 KB
testcase_15 AC 267 ms
33,792 KB
testcase_16 AC 349 ms
39,168 KB
testcase_17 AC 236 ms
26,496 KB
testcase_18 AC 355 ms
39,680 KB
testcase_19 AC 173 ms
23,296 KB
testcase_20 AC 369 ms
39,424 KB
testcase_21 AC 240 ms
27,392 KB
testcase_22 AC 168 ms
40,064 KB
testcase_23 AC 170 ms
39,424 KB
testcase_24 AC 144 ms
35,584 KB
testcase_25 AC 130 ms
36,096 KB
testcase_26 AC 161 ms
41,856 KB
testcase_27 AC 418 ms
43,136 KB
testcase_28 AC 438 ms
43,264 KB
testcase_29 AC 434 ms
43,136 KB
testcase_30 AC 420 ms
43,264 KB
testcase_31 AC 434 ms
43,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local edge = {}
local edgecnt = {}
local l_to_r = {}
for i = 1, n do
  edge[i] = {}
  edgecnt[i] = 0
  l_to_r[i] = true
end

local ea, eb = {}, {}
for i = 1, n do
  local a, b = io.read("*n", "*n")
  ea[i], eb[i] = a, b
  edge[a][i] = true
  edge[b][i] = true
  edgecnt[a] = edgecnt[a] + 1
  edgecnt[b] = edgecnt[b] + 1
end

local tasks = {}
for i = 1, n do
  if edgecnt[i] == 1 then
    table.insert(tasks, i)
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local src = tasks[done]
  local ei = next(edge[src])
  local dst = ea[ei] + eb[ei] - src
  if eb[ei] == src then
    l_to_r[ei] = false
  end
  edge[src][ei] = nil
  edge[dst][ei] = nil
  edgecnt[src] = 0
  edgecnt[dst] = edgecnt[dst] - 1
  if edgecnt[dst] == 1 then
    table.insert(tasks, dst)
  end
end
local spos = 0
for i = 1, n do
  if edgecnt[i] == 2 then
    spos = i
    break
  end
end
tasks = {}
do
  local ei = next(edge[spos])
  local dst = ea[ei] + eb[ei] - spos
  edge[spos][ei] = nil
  if ea[ei] == spos then
    l_to_r[ei] = false
  end
  table.insert(tasks, spos)
end
done = 0
while done < #tasks do
  done = done + 1
  local src = tasks[done]
  local ei = next(edge[src])
  if not ei then break end
  local dst = ea[ei] + eb[ei] - src
  if eb[ei] == src then
    l_to_r[ei] = false
  end
  edge[src][ei] = nil
  edge[dst][ei] = nil
  table.insert(tasks, dst)
end
for i = 1, n do
  print(l_to_r[i] and "->" or "<-")
end
0