結果

問題 No.1647 Travel in Mitaru city 2
ユーザー tamatotamato
提出日時 2021-08-13 22:14:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,839 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 82,968 KB
実行使用メモリ 124,696 KB
最終ジャッジ日時 2024-04-14 18:22:32
合計ジャッジ時間 18,663 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,400 KB
testcase_01 AC 41 ms
54,144 KB
testcase_02 AC 40 ms
54,400 KB
testcase_03 AC 41 ms
56,056 KB
testcase_04 AC 52 ms
65,792 KB
testcase_05 AC 40 ms
54,656 KB
testcase_06 AC 41 ms
54,912 KB
testcase_07 AC 53 ms
66,688 KB
testcase_08 AC 320 ms
120,912 KB
testcase_09 WA -
testcase_10 AC 313 ms
119,324 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 311 ms
117,312 KB
testcase_14 AC 327 ms
121,116 KB
testcase_15 AC 319 ms
120,680 KB
testcase_16 AC 305 ms
115,120 KB
testcase_17 AC 304 ms
116,060 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 324 ms
121,164 KB
testcase_23 AC 325 ms
121,940 KB
testcase_24 AC 327 ms
116,224 KB
testcase_25 AC 298 ms
115,992 KB
testcase_26 AC 328 ms
123,308 KB
testcase_27 AC 331 ms
122,096 KB
testcase_28 AC 336 ms
122,616 KB
testcase_29 AC 339 ms
122,664 KB
testcase_30 AC 299 ms
115,852 KB
testcase_31 AC 339 ms
122,588 KB
testcase_32 WA -
testcase_33 AC 315 ms
116,548 KB
testcase_34 AC 333 ms
124,696 KB
testcase_35 WA -
testcase_36 AC 344 ms
122,476 KB
testcase_37 AC 333 ms
122,392 KB
testcase_38 AC 327 ms
116,396 KB
testcase_39 AC 300 ms
115,932 KB
testcase_40 AC 311 ms
115,560 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 45 ms
61,916 KB
testcase_44 AC 48 ms
68,904 KB
testcase_45 WA -
testcase_46 AC 297 ms
113,852 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9
NN = 2*10 ** 5


def main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline

    H, W, N = map(int, input().split())
    adj = [[] for _ in range(H + W + 1)]
    E_idx = {}
    for i in range(1, N+1):
        x, y = map(int, input().split())
        E_idx[x * (NN+1) + y + H] = i
        E_idx[(y + H) * (NN+1) + x] = i
        adj[x].append(y + H)
        adj[y + H].append(x)

    seen = [-1] * (H + W + 1)
    par = [0] * (H + W + 1)
    for v0 in range(1, H+1):
        if seen[v0] != -1:
            continue
        que = deque()
        que.append(v0)
        seen[v0] = 0
        B = []
        while que:
            v = que.popleft()
            for u in adj[v]:
                if seen[u] == -1:
                    seen[u] = seen[v] + 1
                    par[u] = v
                    que.append(u)
                else:
                    if u != par[v]:
                        B.append((u, v))
        if B:
            u, v = B[0]
            U = []
            uu = u
            while uu != v0:
                U.append(uu)
                uu = par[uu]
            V = []
            vv = v
            while vv != 0:
                V.append(vv)
                vv = par[vv]
            V.reverse()
            U.extend(V)
            if U[0] > H:
                U_new = [U[-1]] + U[:-1]
                U = U_new
            ans = []
            L = len(U)
            for i in range(L):
                x, y = U[i], U[(i+1)%L]
                if x > y:
                    x, y = y, x
                #print(x, y)
                ans.append(E_idx[x * (NN+1) + y])
            assert len(ans) % 2 == 0
            print(len(ans))
            print(*ans)
            exit()
    #print(seen)
    print(-1)


if __name__ == '__main__':
    main()
0