結果

問題 No.1605 Matrix Shape
ユーザー 炭酸水炭酸水
提出日時 2022-05-19 23:10:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,046 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 11,900 KB
実行使用メモリ 62,684 KB
最終ジャッジ日時 2023-10-19 07:34:26
合計ジャッジ時間 21,972 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,232 KB
testcase_01 AC 30 ms
10,232 KB
testcase_02 AC 30 ms
10,232 KB
testcase_03 AC 30 ms
10,232 KB
testcase_04 AC 36 ms
10,232 KB
testcase_05 AC 30 ms
10,232 KB
testcase_06 AC 31 ms
10,232 KB
testcase_07 AC 30 ms
10,232 KB
testcase_08 AC 31 ms
10,232 KB
testcase_09 AC 30 ms
10,232 KB
testcase_10 AC 30 ms
10,232 KB
testcase_11 AC 30 ms
10,232 KB
testcase_12 AC 31 ms
10,232 KB
testcase_13 AC 30 ms
10,232 KB
testcase_14 AC 30 ms
10,232 KB
testcase_15 AC 29 ms
10,232 KB
testcase_16 AC 31 ms
10,232 KB
testcase_17 AC 30 ms
10,232 KB
testcase_18 AC 31 ms
10,232 KB
testcase_19 TLE -
testcase_20 AC 1,526 ms
36,840 KB
testcase_21 AC 1,474 ms
35,780 KB
testcase_22 AC 1,948 ms
60,848 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 719 ms
10,324 KB
testcase_26 AC 722 ms
10,324 KB
testcase_27 AC 740 ms
10,324 KB
testcase_28 AC 737 ms
10,348 KB
testcase_29 AC 730 ms
10,324 KB
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
P_C = {}
C_P = {}

v = set()
z = {}
for _ in range(n):
    x, y = map(int, input().split())
    if x in v:
        z[x] += 1
    else:
        v.add(x)
        z[x] = 1
    if y in v:
        z[y] -= 1
    else:
        v.add(y)
        z[y] = -1
    
    x_P = C_P.get(x, 0)
    y_P = C_P.get(y, 0)
    
    if x_P == 0 and y_P == 0:
        C_P[x] = x
        C_P[y] = x
        P_C[x] = [x, y]
    
    elif x_P == 0:
        C_P[x] = y_P
        P_C[y_P].append(x)
    
    elif y_P == 0:
        C_P[y] = x_P
        P_C[x_P].append(y)
    
    elif x_P != y_P:
        P = P_C[y_P].copy()
        for i in P:
            C_P[i] = x_P
        P_C[x_P] += P
        del P_C[y_P]

count_p1 = 0
count_0 = 0
count_m1 = 0

for i in v:
    if z[i] == 0:
        count_0 += 1
    elif z[i] == 1:
        count_p1 += 1
    elif z[i] == -1:
        count_m1 += 1

if len(P_C) ==1 and count_m1 == 1 and count_p1 == 1 and count_0 == len(v) - 2:
    print(1)
elif len(P_C) ==1 and count_0 == len(v):
    print(len(v))
else:
    print(0)
0