結果

問題 No.2664 Prime Sum
ユーザー chineristACchineristAC
提出日時 2024-03-09 00:01:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 73,352 KB
最終ジャッジ日時 2024-03-09 00:01:17
合計ジャッジ時間 3,731 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
56,248 KB
testcase_01 AC 44 ms
56,248 KB
testcase_02 AC 46 ms
56,248 KB
testcase_03 AC 50 ms
61,796 KB
testcase_04 AC 46 ms
56,248 KB
testcase_05 AC 57 ms
68,036 KB
testcase_06 AC 54 ms
65,980 KB
testcase_07 AC 52 ms
63,896 KB
testcase_08 AC 49 ms
61,796 KB
testcase_09 AC 46 ms
58,340 KB
testcase_10 AC 52 ms
63,932 KB
testcase_11 AC 46 ms
56,248 KB
testcase_12 AC 52 ms
63,932 KB
testcase_13 AC 57 ms
68,036 KB
testcase_14 AC 66 ms
73,352 KB
testcase_15 AC 67 ms
73,340 KB
testcase_16 AC 66 ms
73,352 KB
testcase_17 AC 51 ms
63,932 KB
testcase_18 AC 51 ms
63,932 KB
testcase_19 AC 50 ms
63,932 KB
testcase_20 AC 53 ms
63,932 KB
testcase_21 AC 57 ms
68,036 KB
testcase_22 AC 54 ms
65,980 KB
testcase_23 AC 67 ms
73,352 KB
testcase_24 AC 45 ms
56,248 KB
testcase_25 AC 45 ms
56,248 KB
testcase_26 AC 46 ms
58,340 KB
testcase_27 AC 50 ms
63,932 KB
testcase_28 AC 46 ms
58,340 KB
testcase_29 AC 49 ms
61,796 KB
testcase_30 AC 46 ms
56,248 KB
testcase_31 AC 46 ms
56,248 KB
testcase_32 AC 46 ms
58,340 KB
testcase_33 AC 49 ms
61,796 KB
testcase_34 AC 49 ms
61,796 KB
testcase_35 AC 50 ms
63,932 KB
testcase_36 AC 44 ms
56,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

n,m = mi()
uf = UnionFindVerSize(2*n)
for i in range(m):
    a,b = mi()
    a,b = a-1,b-1
    uf.unite(2*a,2*b+1)
    uf.unite(2*a+1,2*b)

    if uf.is_same_group(2*a,2*a+1):
        print("No")
        exit()
print("Yes")

0