結果

問題 No.2563 色ごとのグループ
ユーザー KoiKoi
提出日時 2023-12-02 15:37:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 550 ms / 2,000 ms
コード長 585 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 123,324 KB
最終ジャッジ日時 2023-12-02 15:37:33
合計ジャッジ時間 8,582 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,612 KB
testcase_01 AC 40 ms
55,612 KB
testcase_02 AC 40 ms
55,612 KB
testcase_03 AC 40 ms
55,612 KB
testcase_04 AC 43 ms
55,612 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 40 ms
55,612 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 40 ms
55,612 KB
testcase_09 AC 42 ms
55,608 KB
testcase_10 AC 40 ms
55,608 KB
testcase_11 AC 42 ms
55,608 KB
testcase_12 AC 41 ms
55,608 KB
testcase_13 AC 41 ms
55,608 KB
testcase_14 AC 73 ms
73,744 KB
testcase_15 AC 74 ms
74,124 KB
testcase_16 AC 74 ms
73,996 KB
testcase_17 AC 75 ms
73,740 KB
testcase_18 AC 55 ms
66,772 KB
testcase_19 AC 86 ms
76,540 KB
testcase_20 AC 98 ms
78,676 KB
testcase_21 AC 84 ms
76,796 KB
testcase_22 AC 84 ms
76,540 KB
testcase_23 AC 91 ms
76,796 KB
testcase_24 AC 197 ms
92,344 KB
testcase_25 AC 182 ms
93,528 KB
testcase_26 AC 239 ms
107,112 KB
testcase_27 AC 249 ms
122,360 KB
testcase_28 AC 271 ms
109,420 KB
testcase_29 AC 306 ms
122,276 KB
testcase_30 AC 323 ms
123,324 KB
testcase_31 AC 328 ms
122,300 KB
testcase_32 AC 331 ms
122,292 KB
testcase_33 AC 539 ms
117,464 KB
testcase_34 AC 550 ms
117,312 KB
testcase_35 AC 501 ms
117,316 KB
testcase_36 AC 497 ms
117,716 KB
testcase_37 AC 524 ms
117,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,deque
N,M=map(int,input().split())
C=list(map(int,input().split()))
G=defaultdict(list)
for i in range(M):
    u,v=map(int,input().split())
    if(C[u-1]==C[v-1]):
        G[u].append(v)
        G[v].append(u)
#連結成分の個数-色の種類数
T=1
c=0
seen=[False]*(N+1)
while T<=N:
    que=deque([T])
    seen[T]=True
    while len(que):
        p=que.popleft()
        for q in G[p]:
            if(not seen[q]):
                seen[q]=True
                que.append(q)
    while T<=N and seen[T]:
        T+=1
    c+=1
print(c-len(set(C)))
0