結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー |
![]() |
提出日時 | 2023-08-04 22:00:46 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 936 bytes |
コンパイル時間 | 91 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 48,640 KB |
最終ジャッジ日時 | 2024-10-14 19:58:26 |
合計ジャッジ時間 | 7,310 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 13 WA * 18 |
ソースコード
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))