結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー |
![]() |
提出日時 | 2023-08-04 22:07:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 658 bytes |
コンパイル時間 | 195 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 31,856 KB |
最終ジャッジ日時 | 2024-10-14 20:05:23 |
合計ジャッジ時間 | 8,951 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 WA * 16 |
ソースコード
class UF:def __init__(self,n):self.p = [-1]*ndef f(self,x):if self.p[x]<0: return xelse: self.p[x] = self.f(self.p[x]); return self.p[x]def u(self,x,y):x = self.f(x); y = self.f(y)if x==y: returnif -self.p[x]<-self.p[y]: x,y = y,xself.p[x] += self.p[y]; self.p[y] = xn,m = map(int,input().split())a = [0]*n; b = [0]*n; c = []; uf = UF(n)for _ in range(m):u,v = map(int,input().split())a[u-1] += 1; b[v-1] += 1; uf.u(u-1,v-1)ans = len(set(uf.f(i) for i in range(n)))-1for u,v in zip(a,b):if u>v: c.append(u-v)if u==v==0: ans -= 1print(ans+max(sum(c)-1,0))