結果

問題 No.2200 Weird Shortest Path
ユーザー googol_S0googol_S0
提出日時 2023-01-28 19:32:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 825 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 121,824 KB
最終ジャッジ日時 2023-09-11 07:34:22
合計ジャッジ時間 21,743 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,236 KB
testcase_01 AC 76 ms
71,380 KB
testcase_02 AC 78 ms
71,176 KB
testcase_03 AC 91 ms
75,436 KB
testcase_04 AC 110 ms
76,984 KB
testcase_05 AC 75 ms
71,392 KB
testcase_06 AC 83 ms
74,992 KB
testcase_07 AC 89 ms
75,768 KB
testcase_08 AC 110 ms
76,924 KB
testcase_09 AC 108 ms
76,936 KB
testcase_10 AC 80 ms
70,972 KB
testcase_11 AC 79 ms
71,412 KB
testcase_12 AC 79 ms
71,212 KB
testcase_13 AC 79 ms
71,096 KB
testcase_14 AC 78 ms
71,400 KB
testcase_15 AC 106 ms
77,032 KB
testcase_16 AC 78 ms
71,260 KB
testcase_17 AC 305 ms
88,880 KB
testcase_18 AC 466 ms
101,520 KB
testcase_19 AC 700 ms
105,624 KB
testcase_20 AC 718 ms
114,284 KB
testcase_21 AC 365 ms
97,456 KB
testcase_22 AC 426 ms
99,064 KB
testcase_23 AC 735 ms
110,004 KB
testcase_24 AC 212 ms
84,188 KB
testcase_25 AC 686 ms
106,112 KB
testcase_26 AC 731 ms
108,892 KB
testcase_27 AC 330 ms
94,252 KB
testcase_28 AC 571 ms
103,500 KB
testcase_29 AC 750 ms
111,740 KB
testcase_30 AC 721 ms
108,172 KB
testcase_31 AC 479 ms
99,868 KB
testcase_32 AC 797 ms
121,320 KB
testcase_33 AC 815 ms
121,208 KB
testcase_34 AC 825 ms
121,128 KB
testcase_35 AC 816 ms
121,824 KB
testcase_36 AC 816 ms
121,240 KB
testcase_37 AC 814 ms
121,420 KB
testcase_38 AC 808 ms
121,616 KB
testcase_39 AC 499 ms
113,512 KB
testcase_40 AC 413 ms
113,012 KB
testcase_41 AC 447 ms
104,508 KB
testcase_42 AC 414 ms
113,180 KB
testcase_43 AC 447 ms
118,124 KB
testcase_44 AC 458 ms
118,020 KB
testcase_45 AC 445 ms
118,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

belong=list()
group=list()
def init(X):
  global belong
  global group
  belong=list(range(X))
  group=[[i] for i in range(X)]

def unite(x,y):
  if len(group[belong[x]])<len(group[belong[y]]):
    x,y=y,x
  if belong[x]==belong[y]:
    return 0
  z=belong[y]
  V=len(group[z])*len(group[belong[x]])
  for i in range(len(group[z])):
    belong[group[z][-1]]=belong[x]
    group[belong[x]].append(group[z][-1])
    del group[z][-1]
  return V

N,M=map(int,input().split())
init(N)
X=[tuple(map(int,input().split())) for i in range(M)]
X.sort(key=lambda x:x[2])
ANS=0
for i in range(M):
  ANS+=X[i][2]*unite(X[i][0]-1,X[i][1]-1)
print(ANS)
0