結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー flygonflygon
提出日時 2023-08-04 21:48:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,332 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 81,536 KB
最終ジャッジ日時 2024-04-22 20:07:52
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
54,656 KB
testcase_01 AC 47 ms
54,400 KB
testcase_02 AC 45 ms
54,656 KB
testcase_03 AC 43 ms
54,912 KB
testcase_04 AC 94 ms
77,824 KB
testcase_05 AC 125 ms
80,000 KB
testcase_06 AC 128 ms
80,896 KB
testcase_07 AC 99 ms
77,952 KB
testcase_08 AC 108 ms
78,848 KB
testcase_09 AC 134 ms
81,536 KB
testcase_10 AC 139 ms
80,896 KB
testcase_11 AC 119 ms
79,872 KB
testcase_12 AC 134 ms
81,024 KB
testcase_13 AC 118 ms
80,640 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 42 ms
54,656 KB
testcase_19 AC 56 ms
70,528 KB
testcase_20 AC 50 ms
63,360 KB
testcase_21 AC 53 ms
66,048 KB
testcase_22 AC 59 ms
70,016 KB
testcase_23 AC 55 ms
68,992 KB
testcase_24 AC 59 ms
68,096 KB
testcase_25 AC 59 ms
67,584 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 65 ms
72,064 KB
testcase_29 WA -
testcase_30 AC 55 ms
65,536 KB
testcase_31 AC 68 ms
73,600 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

from collections import defaultdict


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [-1] * (n+1)

    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.p[x] > self.p[y]:
            x, y = y, x
        self.p[x] += self.p[y]
        self.p[y] = x

    def same(self, a, b):
        return self.find(a) == self.find(b)

    def group(self):
        d = defaultdict(list)
        for i in range(1, self.n+1):
            par = self.find(i)
            d[par].append(i)
        return d


n,m = map(int,input().split())
graph = [[] for i in range(n+1)]
uf = UnionFind(n)
indeg = [0]*(n+1)
outdeg = [0]*(n+1)
for i in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    indeg[b] += 1
    outdeg[a] += 1

ans = 0
for i in range(1,n+1):
    if indeg[i] >= outdeg[i]:
        ans += indeg[i] - outdeg[i]

print(max(ans-1, 0))
0