結果

問題 No.483 マッチ並べ
ユーザー H3PO4H3PO4
提出日時 2020-11-25 18:59:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 43,376 KB
最終ジャッジ日時 2023-10-01 01:52:19
合計ジャッジ時間 16,611 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 207 ms
42,960 KB
testcase_01 AC 208 ms
43,080 KB
testcase_02 AC 204 ms
42,948 KB
testcase_03 AC 207 ms
43,208 KB
testcase_04 AC 206 ms
43,152 KB
testcase_05 AC 207 ms
43,060 KB
testcase_06 AC 207 ms
43,360 KB
testcase_07 AC 202 ms
43,152 KB
testcase_08 AC 203 ms
43,376 KB
testcase_09 AC 199 ms
43,060 KB
testcase_10 AC 206 ms
43,104 KB
testcase_11 AC 205 ms
43,100 KB
testcase_12 AC 206 ms
43,108 KB
testcase_13 AC 204 ms
42,996 KB
testcase_14 AC 200 ms
43,132 KB
testcase_15 AC 202 ms
43,176 KB
testcase_16 AC 204 ms
43,160 KB
testcase_17 AC 201 ms
43,068 KB
testcase_18 AC 200 ms
42,744 KB
testcase_19 AC 201 ms
42,948 KB
testcase_20 AC 196 ms
43,308 KB
testcase_21 AC 197 ms
43,088 KB
testcase_22 AC 198 ms
43,120 KB
testcase_23 AC 202 ms
43,188 KB
testcase_24 AC 202 ms
43,232 KB
testcase_25 AC 200 ms
43,188 KB
testcase_26 AC 198 ms
43,184 KB
testcase_27 AC 200 ms
43,164 KB
testcase_28 AC 205 ms
43,204 KB
testcase_29 AC 202 ms
43,308 KB
testcase_30 AC 202 ms
42,988 KB
testcase_31 AC 204 ms
43,224 KB
testcase_32 AC 198 ms
43,208 KB
testcase_33 AC 198 ms
42,980 KB
testcase_34 AC 198 ms
43,164 KB
testcase_35 AC 200 ms
43,376 KB
testcase_36 AC 200 ms
43,192 KB
testcase_37 AC 201 ms
43,192 KB
testcase_38 AC 204 ms
43,076 KB
testcase_39 AC 207 ms
43,100 KB
testcase_40 AC 206 ms
43,156 KB
testcase_41 AC 208 ms
43,196 KB
testcase_42 AC 205 ms
43,096 KB
testcase_43 AC 207 ms
43,220 KB
testcase_44 AC 210 ms
43,112 KB
testcase_45 AC 205 ms
43,192 KB
testcase_46 AC 198 ms
43,036 KB
testcase_47 AC 198 ms
43,352 KB
testcase_48 AC 232 ms
43,128 KB
testcase_49 AC 201 ms
43,092 KB
testcase_50 AC 198 ms
43,228 KB
testcase_51 AC 198 ms
42,936 KB
testcase_52 AC 198 ms
43,124 KB
testcase_53 AC 200 ms
43,048 KB
testcase_54 AC 203 ms
43,144 KB
testcase_55 AC 210 ms
42,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

N = int(input())
node = set()
RC = [tuple(map(int, input().split())) for _ in range(N)]
for r0, c0, r1, c1 in RC:
    node.add((r0, c0))
    node.add((r1, c1))
node_d = {rc: i for i, rc in enumerate(node)}

size = len(node_d)
frm, to = [], []
for r0, c0, r1, c1 in RC:
    frm.append(node_d[(r0, c0)])
    to.append(node_d[(r1, c1)])
matr = csr_matrix(([1] * N, (frm, to)), shape=(size, size))
p, labels = connected_components(matr)

conn_node = [0] * p
conn_edge = [0] * p

for x in labels:
    conn_node[x] += 1
for r0, c0, _, _ in RC:
    conn_edge[labels[node_d[(r0, c0)]]] += 1

for n,e in zip(conn_node, conn_edge):
    if n < e:
        print('NO')
        exit()
print('YES')
0