結果

問題 No.1023 Cyclic Tour
ユーザー maspymaspy
提出日時 2020-04-10 23:00:00
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 990 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 163,092 KB
最終ジャッジ日時 2024-09-15 23:36:44
合計ジャッジ時間 40,586 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 48 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components
import numpy as np
N, M = map(int, readline().split())
AB1 = []
AB2 = []
m = map(int, read().split())
for a, b, c in zip(m, m, m):
    if c == 1:
        AB1.append((a, b))
    else:
        AB2.append((a, b))

if AB1:
    A1, B1 = zip(*AB1)
else:
    A1, B1 = (), ()
if AB2:
    A2, B2 = zip(*AB2)
else:
    A2, B2 = (), ()

U = A1 + B1 + A2
V = B1 + A1 + B2
G = csr_matrix(([1] * len(U), (U, V)), (N + 1, N + 1))
_, comp = connected_components(G, directed=True, connection='strong')
comp_size = np.bincount(comp)
C = comp.max()
comp = list(comp)

n_edges = [0] * (C + 1)
for a, b in AB1 + AB2:
    ca = comp[a]
    cb = comp[b]
    if ca != cb:
        continue
    n_edges[ca] += 1

bl = any(x <= y for x, y in zip(comp_size, n_edges))
answer = 'Yes' if bl else 'No'
print(answer)
0