結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,880 KB
testcase_01 AC 25 ms
10,880 KB
testcase_02 AC 25 ms
10,880 KB
testcase_03 AC 25 ms
10,880 KB
testcase_04 AC 219 ms
27,648 KB
testcase_05 AC 423 ms
43,264 KB
testcase_06 AC 461 ms
45,440 KB
testcase_07 AC 288 ms
32,128 KB
testcase_08 AC 326 ms
35,456 KB
testcase_09 AC 503 ms
48,128 KB
testcase_10 AC 483 ms
47,744 KB
testcase_11 AC 353 ms
38,400 KB
testcase_12 AC 498 ms
48,768 KB
testcase_13 AC 343 ms
35,712 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 26 ms
10,752 KB
testcase_19 AC 153 ms
23,936 KB
testcase_20 AC 49 ms
13,440 KB
testcase_21 AC 94 ms
17,408 KB
testcase_22 AC 134 ms
22,528 KB
testcase_23 AC 135 ms
22,144 KB
testcase_24 AC 125 ms
20,224 KB
testcase_25 AC 109 ms
19,456 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 137 ms
20,992 KB
testcase_29 WA -
testcase_30 AC 79 ms
16,256 KB
testcase_31 AC 153 ms
23,424 KB
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]*(N+1)

ANS=0

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


print(max(0,ANS-1))


LIST=[]
for i in range(1,N+1):
    if find(i)==i:
        LIST.append(INP[i])

LIST.sort(reverse=True)

0