結果

問題 No.1023 Cyclic Tour
ユーザー chocorusk
提出日時 2020-04-07 18:17:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 950 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 39,936 KB
最終ジャッジ日時 2024-07-07 20:10:44
合計ジャッジ時間 7,963 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 2 RE * 47
権限があれば一括ダウンロードができます

ソースコード

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]:
        swap(x, y)
    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