結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | puzneko |
提出日時 | 2021-10-25 00:37:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,124 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 142,776 KB |
最終ジャッジ日時 | 2024-10-02 07:38:45 |
合計ジャッジ時間 | 56,409 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 45 ms
52,864 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 44 ms
53,504 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 949 ms
116,456 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
ソースコード
from sys import stdin from heapq import heappush, heappop from sys import setrecursionlimit setrecursionlimit(10000000) w, h, n, *indata = map(int, stdin.read().split()) offset = 0 hq = [] xylist = [(-1,-1)] for i in range(n): y, x = indata[offset + 2*i],indata[offset + 2*i+1] heappush(hq, (y, x, i+1)) xylist.append((x,y)) par = [i for i in range(h+1)] rank = [0 for i in range(h+1)] def root(x): if par[x] == x: return x else: par[x] = root(par[x]) return par[x] def unite(x,y): karix = root(x) kariy = root(y) if karix == kariy: return 0 if rank[karix] < rank[kariy]: par[karix] = kariy else: par[kariy] = karix if rank[karix] == rank[kariy]: rank[karix] += 1 def same(x,y): return root(x) == root(y) prey = -1 prex = -1 preind = -1 samexlist = [[] for j in range(h+1)] g = [[] for i in range(n+1)] while hq: y, x, ind = heappop(hq) if prey == y: if same(prex,x): g[preind].append(ind) ind2 = samexlist[x][-1] g[ind2].append(ind) g[ind].append(ind2) que = [(ind,0)] route = [ind] check = [False for i in range(n+1)] check[ind] = True while que: now, inout = que.pop() if now == preind: route.append(now) route.append(ind) ans = [ind] lenroute = len(route) parity = 0 for i in range(1,lenroute): if parity: if xylist[ans[-1]][0] == xylist[route[i]][0]: ans.pop() ans.append(route[i]) else: ans.append(route[i]) parity = parity ^ 1 else: if xylist[ans[-1]][1] == xylist[route[i]][1]: ans.pop() ans.append(route[i]) else: ans.append(route[i]) parity = parity ^ 1 ans.pop() ansx = len(ans) L=[str(i) for i in ans] L=' '.join(L) print(L) exit() if inout == 0: que.append((now,1)) route.append(now) for i in g[now]: if not check[i]: check[i] = True que.append((i,0)) else: route.pop() else: unite(prex,x) g[ind].append(preind) g[preind].append(ind) else: prey = y if samexlist[x]: ind2 = samexlist[x][-1] g[ind2].append(ind) g[ind].append(ind2) samexlist[x].append(ind) prex = x preind = ind print("{}".format(-1))