結果
問題 |
No.2403 "Eight" Bridges of Königsberg
|
ユーザー |
![]() |
提出日時 | 2023-08-04 21:42:56 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 699 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 108,416 KB |
最終ジャッジ日時 | 2024-10-14 19:41:08 |
合計ジャッジ時間 | 5,105 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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]) ans=0 cnt1=0 cnt2=0 for x,y in G: ans+=x if y: cnt1=1 else: cnt2+=1 if cnt1: ans-=1 print(ans+max(0,cnt2-1))