結果

問題 No.1023 Cyclic Tour
ユーザー chocoruskchocorusk
提出日時 2020-04-07 18:29:55
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 1,241 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,724 KB
実行使用メモリ 48,968 KB
最終ジャッジ日時 2023-09-22 03:53:01
合計ジャッジ時間 49,203 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,700 KB
testcase_01 AC 22 ms
8,528 KB
testcase_02 AC 21 ms
8,528 KB
testcase_03 AC 19 ms
8,704 KB
testcase_04 AC 421 ms
13,200 KB
testcase_05 AC 420 ms
13,200 KB
testcase_06 AC 448 ms
13,432 KB
testcase_07 AC 439 ms
13,240 KB
testcase_08 AC 641 ms
33,176 KB
testcase_09 AC 652 ms
32,340 KB
testcase_10 AC 631 ms
32,540 KB
testcase_11 AC 681 ms
33,968 KB
testcase_12 AC 669 ms
36,952 KB
testcase_13 AC 642 ms
35,036 KB
testcase_14 AC 638 ms
35,000 KB
testcase_15 AC 679 ms
35,696 KB
testcase_16 AC 1,056 ms
48,448 KB
testcase_17 AC 1,071 ms
48,968 KB
testcase_18 AC 1,085 ms
48,468 KB
testcase_19 AC 1,055 ms
47,352 KB
testcase_20 AC 1,129 ms
35,380 KB
testcase_21 AC 1,053 ms
35,740 KB
testcase_22 AC 1,122 ms
40,004 KB
testcase_23 AC 1,174 ms
41,620 KB
testcase_24 AC 1,241 ms
47,460 KB
testcase_25 AC 1,024 ms
35,400 KB
testcase_26 AC 1,030 ms
36,440 KB
testcase_27 AC 987 ms
35,424 KB
testcase_28 AC 1,209 ms
46,436 KB
testcase_29 AC 1,150 ms
47,764 KB
testcase_30 AC 1,197 ms
46,544 KB
testcase_31 AC 1,129 ms
43,224 KB
testcase_32 AC 1,117 ms
45,056 KB
testcase_33 AC 1,210 ms
45,512 KB
testcase_34 AC 314 ms
18,528 KB
testcase_35 AC 707 ms
22,968 KB
testcase_36 AC 1,113 ms
37,248 KB
testcase_37 AC 1,072 ms
42,052 KB
testcase_38 AC 1,082 ms
45,796 KB
testcase_39 AC 1,146 ms
41,752 KB
testcase_40 AC 1,128 ms
42,448 KB
testcase_41 AC 1,133 ms
42,340 KB
testcase_42 AC 1,051 ms
35,912 KB
testcase_43 AC 1,123 ms
45,968 KB
testcase_44 AC 525 ms
22,524 KB
testcase_45 AC 646 ms
37,520 KB
testcase_46 AC 557 ms
37,548 KB
testcase_47 AC 497 ms
21,760 KB
testcase_48 AC 985 ms
36,264 KB
testcase_49 AC 963 ms
36,236 KB
testcase_50 AC 980 ms
36,080 KB
testcase_51 AC 964 ms
36,128 KB
testcase_52 AC 992 ms
38,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n, m=map(int, input().split())
par=[i for i in range(n)]
sz=[1]*n
def find(x):
    if x==par[x]:
        return x
    par[x]=find(par[x])
    return par[x]
def unite(x, y):
    x=find(x)
    y=find(y)
    if x==y:
        return False
    if sz[x]>sz[y]:
        x, y=y, x
    sz[y]+=sz[x]
    par[x]=y
    return True
e=[]
for _ in range(m):
    a, b, c=map(int, input().split())
    a-=1
    b-=1
    if c==1:
        if not unite(a, b):
            print("Yes")
            exit()
    else:
        e.append((a, b))
g=[[] for i in range(n)]
deg=[0]*n
for p in e:
    x=find(p[0])
    y=find(p[1])
    g[x].append(y)
    deg[y]+=1
que=deque()
for x in range(n):
    if deg[x]==0:
        que.appendleft(x)
while len(que)!=0:
    x=que.popleft()
    for y in g[x]:
        deg[y]-=1
        if deg[y]==0:
            que.appendleft(y)
for x in range(n):
    if deg[x]>0:
        print("Yes")
        exit()
print("No")
0