結果
問題 |
No.2403 "Eight" Bridges of Königsberg
|
ユーザー |
![]() |
提出日時 | 2023-08-04 21:41:20 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 756 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 108,800 KB |
最終ジャッジ日時 | 2024-10-14 19:39:31 |
合計ジャッジ時間 | 4,678 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 WA * 19 |
ソースコード
from sys import stdin input=lambda :stdin.readline()[:-1] n,m=map(int,input().split()) edge=[[] for i in range(n)] IN=[0]*n OUT=[0]*n for i in range(m): a,b=map(lambda x:int(x)-1,input().split()) IN[a]+=1 OUT[b]+=1 edge[a].append(b) edge[b].append(a) G=[] seen=[0]*n for i in range(n): if seen[i]: continue todo=[i] seen[i]=1 res=0 flag=False while todo: v=todo.pop() if IN[v]>OUT[v]: flag=True res+=IN[v]-OUT[v] for u in edge[v]: if seen[u]==0: seen[u]=1 todo.append(u) G.append([res,flag]) if len(G)==1: ans=G[0][0] if G[0][1]: ans-=1 print(ans) exit() ans=0 cnt1=0 cnt2=0 for x,y in G: ans+=x if y: ans-=1 else: cnt2+=1 print(ans+max(0,cnt2-1))