結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー titiatitia
提出日時 2023-08-04 22:00:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 48,640 KB
最終ジャッジ日時 2024-04-22 20:18:12
合計ジャッジ時間 6,899 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 33 ms
10,624 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 223 ms
27,520 KB
testcase_05 AC 428 ms
43,136 KB
testcase_06 AC 468 ms
45,184 KB
testcase_07 AC 287 ms
32,000 KB
testcase_08 AC 333 ms
35,328 KB
testcase_09 AC 532 ms
48,000 KB
testcase_10 AC 492 ms
47,360 KB
testcase_11 AC 375 ms
38,144 KB
testcase_12 AC 520 ms
48,640 KB
testcase_13 AC 344 ms
35,584 KB
testcase_14 AC 28 ms
10,752 KB
testcase_15 AC 27 ms
10,624 KB
testcase_16 WA -
testcase_17 AC 26 ms
10,752 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 #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())

E=[list(map(int,input().split())) for i in range(M)]

IN=[0]*(N+1)
OUT=[0]*(N+1)

# UnionFind

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+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 a,b in E:
    Union(a,b)

LEN=0
for i in range(1,N+1):
    if find(i)==i:
        LEN+=1

for a,b in E:
    IN[a]+=1
    OUT[b]+=1

INP=0

for i in range(1,N+1):
    if IN[i]>OUT[i]:
        INP+=IN[i]-OUT[i]


print(max(INP-1,LEN-1))
0