結果
問題 | No.1605 Matrix Shape |
ユーザー | titia |
提出日時 | 2021-07-17 01:57:49 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,088 ms / 2,000 ms |
コード長 | 1,483 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 11,016 KB |
実行使用メモリ | 82,924 KB |
最終ジャッジ日時 | 2023-09-20 18:18:39 |
合計ジャッジ時間 | 16,666 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 83 ms
19,320 KB |
testcase_01 | AC | 82 ms
19,420 KB |
testcase_02 | AC | 39 ms
19,468 KB |
testcase_03 | AC | 82 ms
19,304 KB |
testcase_04 | AC | 40 ms
19,300 KB |
testcase_05 | AC | 83 ms
19,344 KB |
testcase_06 | AC | 81 ms
19,472 KB |
testcase_07 | AC | 39 ms
19,408 KB |
testcase_08 | AC | 84 ms
19,272 KB |
testcase_09 | AC | 81 ms
19,420 KB |
testcase_10 | AC | 84 ms
19,336 KB |
testcase_11 | AC | 81 ms
19,360 KB |
testcase_12 | AC | 81 ms
19,360 KB |
testcase_13 | AC | 85 ms
19,436 KB |
testcase_14 | AC | 81 ms
19,360 KB |
testcase_15 | AC | 82 ms
19,460 KB |
testcase_16 | AC | 81 ms
19,460 KB |
testcase_17 | AC | 82 ms
19,372 KB |
testcase_18 | AC | 81 ms
19,292 KB |
testcase_19 | AC | 1,088 ms
82,796 KB |
testcase_20 | AC | 896 ms
65,336 KB |
testcase_21 | AC | 817 ms
45,872 KB |
testcase_22 | AC | 698 ms
45,944 KB |
testcase_23 | AC | 1,053 ms
82,924 KB |
testcase_24 | AC | 982 ms
45,904 KB |
testcase_25 | AC | 519 ms
40,308 KB |
testcase_26 | AC | 519 ms
40,256 KB |
testcase_27 | AC | 498 ms
38,568 KB |
testcase_28 | AC | 401 ms
38,540 KB |
testcase_29 | AC | 499 ms
38,796 KB |
testcase_30 | AC | 834 ms
65,424 KB |
testcase_31 | AC | 747 ms
45,984 KB |
testcase_32 | AC | 680 ms
55,804 KB |
testcase_33 | AC | 582 ms
45,640 KB |
testcase_34 | AC | 446 ms
46,452 KB |
testcase_35 | AC | 735 ms
40,600 KB |
testcase_36 | AC | 469 ms
32,620 KB |
ソースコード
# なぜか、「終点と終点の前の頂点」の組としてありうる個数を数えようとしていたのはおかしい。 # 行列の積なんだから始点と終点です。はい。 # その後の考察もおかしかった。オイラー路に対する理解もおかしかった。 import sys input = sys.stdin.readline N=int(input()) HW=[tuple(map(int,input().split())) for i in range(N)] DEG=[0]*(2*10**5+1) # UnionFind Group = [i for i in range(2*10**5+1)] # グループ分け Nodes = [1]*(2*10**5+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for h,w in HW: Union(h,w) DEG[h]+=1 DEG[w]-=1 X=find(HW[0][0]) for h,w in HW: if find(h)!=X or find(w)!=X: print(0) exit() one=0 minus=0 other=0 for i in range(2*10**5+1): if DEG[i]==1: one+=1 elif DEG[i]==-1: minus+=1 elif DEG[i]!=0: other+=1 if other!=0: print(0) elif one==0 and minus==0: print(len(set([h for h,w in HW])|set([w for h,w in HW]))) elif one==1 and minus==1: print(1) else: print(0)