提出 #5469397
ソースコード 拡げる
import sys
sys.setrecursionlimit(10**6)
# 連結成分
# UF tree
N,M = map(int,input().split())
n_component = N
root = list(range(N+1))
depth = [0] * (N+1)
def find_root(x):
y = root[x]
if x == y:
return x
z = find_root(y)
root[x] = z
return z
def merge(x,y):
global n_component
xx = find_root(x)
yy = find_root(y)
if xx == yy:
return
n_component -= 1
if depth[xx] >= depth[yy]:
root[yy] = xx
depth[xx] += 1
else:
root[xx] = yy
depth[yy] += 1
for _ in range(M):
x,y,z = [int(x) for x in input().split()]
merge(x,y)
answer = n_component
print(answer)
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - 1 or 2 |
| ユーザ | maspy |
| 言語 | Python (3.4.3) |
| 得点 | 500 |
| コード長 | 647 Byte |
| 結果 | AC |
| 実行時間 | 483 ms |
| メモリ | 9844 KiB |
ジャッジ結果
| セット名 | All | Sample | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 500 / 500 | 0 / 0 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| All | sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17 |
| Sample | sample_01, sample_02, sample_03 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| sample_01 | AC | 17 ms | 3064 KiB |
| sample_02 | AC | 17 ms | 3064 KiB |
| sample_03 | AC | 23 ms | 7668 KiB |
| testcase_01 | AC | 83 ms | 6004 KiB |
| testcase_02 | AC | 191 ms | 7412 KiB |
| testcase_03 | AC | 460 ms | 7796 KiB |
| testcase_04 | AC | 476 ms | 7668 KiB |
| testcase_05 | AC | 306 ms | 3064 KiB |
| testcase_06 | AC | 469 ms | 7668 KiB |
| testcase_07 | AC | 483 ms | 7796 KiB |
| testcase_08 | AC | 475 ms | 9844 KiB |
| testcase_09 | AC | 396 ms | 7176 KiB |
| testcase_10 | AC | 50 ms | 3316 KiB |
| testcase_11 | AC | 414 ms | 5748 KiB |
| testcase_12 | AC | 410 ms | 7796 KiB |
| testcase_13 | AC | 410 ms | 7668 KiB |
| testcase_14 | AC | 431 ms | 7796 KiB |
| testcase_15 | AC | 395 ms | 4212 KiB |
| testcase_16 | AC | 17 ms | 3064 KiB |
| testcase_17 | AC | 23 ms | 7668 KiB |