結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-08-04 22:11:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,020 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 78,768 KB
最終ジャッジ日時 2024-04-22 20:28:34
合計ジャッジ時間 4,511 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,640 KB
testcase_01 AC 32 ms
52,252 KB
testcase_02 AC 32 ms
53,620 KB
testcase_03 AC 32 ms
52,688 KB
testcase_04 AC 153 ms
77,020 KB
testcase_05 AC 203 ms
77,192 KB
testcase_06 AC 222 ms
77,072 KB
testcase_07 AC 158 ms
76,868 KB
testcase_08 AC 189 ms
77,272 KB
testcase_09 AC 224 ms
77,308 KB
testcase_10 AC 208 ms
77,060 KB
testcase_11 AC 193 ms
76,680 KB
testcase_12 AC 216 ms
76,784 KB
testcase_13 AC 197 ms
77,164 KB
testcase_14 AC 32 ms
52,364 KB
testcase_15 AC 30 ms
53,564 KB
testcase_16 WA -
testcase_17 AC 31 ms
52,276 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]


n,m = map(int,input().split())

uf = Unionfind(n)

nums = [0]*n
for i in range(m):
    u,v = [int(x)-1 for x in input().split()]
    nums[u] += 1
    nums[v] -= 1
    uf.union(u,v)

grs = 0
for i in range(n):
    if uf.find(i) == i:
        grs += 1

count = 0
for num in nums:
    if num > 0:
        count += num

ans = grs -1 
if count > ans + 1:
    ans = count - 1
print(ans)
0