結果
| 問題 | 
                            No.1023 Cyclic Tour
                             | 
                    
| コンテスト | |
| ユーザー | 
                             maspy
                         | 
                    
| 提出日時 | 2020-04-10 22:56:53 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 912 bytes | 
| コンパイル時間 | 118 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 105,104 KB | 
| 最終ジャッジ日時 | 2024-09-15 23:25:03 | 
| 合計ジャッジ時間 | 88,028 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge6 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 46 RE * 3 | 
ソースコード
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))
A1, B1 = zip(*AB1)
A2, B2 = zip(*AB2)
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)
            
            
            
        
            
maspy