結果
問題 | No.2403 "Eight" Bridges of Königsberg |
ユーザー | mono_0812 |
提出日時 | 2023-08-04 22:34:08 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,286 bytes |
コンパイル時間 | 95 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 41,040 KB |
最終ジャッジ日時 | 2024-10-14 20:34:45 |
合計ジャッジ時間 | 12,109 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 45 ms
12,416 KB |
testcase_27 | AC | 362 ms
39,696 KB |
testcase_28 | WA | - |
testcase_29 | AC | 99 ms
17,352 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 53 ms
12,800 KB |
testcase_33 | AC | 137 ms
22,280 KB |
testcase_34 | WA | - |
ソースコード
############################################################################################ import bisect,collections,copy,heapq,itertools,math,string,sys,queue,time,random from decimal import Decimal def I(): return input() def IS(): return input().split() def II(): return int(input()) def IIS(): return list(map(int,input().split())) def LIIS(): return list(map(int,input().split())) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] import math def prime_numbers(n): prime = [True for i in range(n+1)] prime[0] = False prime[1] = False sqrt_n = math.ceil(math.sqrt(n)) for i in range(2, sqrt_n): if prime[i]: for j in range(2*i, n+1, i): prime[j] = False numbers=[] for i in range(2,n+1): if prime[i]: numbers.append(i) return numbers def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr INF=float("inf") MOD=998244353 MOD2=10**9+7 #sys.setrecursionlimit(500005) def bit_count(x): return bin(x).count("1") def yesno(f): if f:print("Yes") else:print("No") #################################################### from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) n,m=IIS() li=[0 for i in range(n)] uf=UnionFind(n) for _ in range(m): u,v=IIS() li[u-1]+=1 li[v-1]-=1 uf.union(u-1,v-1) ans=0 cnt2=0 s=uf.all_group_members() for i in s: cnt=0 if len(s[i])>1: cnt2+=1 for j in s[i]: cnt+=abs(li[j]) ans+=max(cnt//2-1,0) print(ans+max(cnt2-1,0)+1)