結果

問題 No.1023 Cyclic Tour
ユーザー maspymaspy
提出日時 2020-04-10 22:56:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 912 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 128,196 KB
最終ジャッジ日時 2023-10-14 03:54:19
合計ジャッジ時間 39,660 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 935 ms
42,952 KB
testcase_01 AC 209 ms
43,208 KB
testcase_02 AC 201 ms
43,080 KB
testcase_03 AC 204 ms
43,112 KB
testcase_04 AC 493 ms
70,396 KB
testcase_05 AC 498 ms
71,408 KB
testcase_06 AC 535 ms
75,012 KB
testcase_07 AC 515 ms
71,760 KB
testcase_08 AC 482 ms
68,068 KB
testcase_09 AC 472 ms
66,648 KB
testcase_10 AC 476 ms
66,116 KB
testcase_11 AC 512 ms
68,140 KB
testcase_12 AC 489 ms
67,124 KB
testcase_13 AC 488 ms
66,584 KB
testcase_14 AC 482 ms
65,632 KB
testcase_15 AC 504 ms
67,084 KB
testcase_16 AC 724 ms
91,968 KB
testcase_17 AC 719 ms
92,812 KB
testcase_18 AC 716 ms
94,660 KB
testcase_19 AC 693 ms
92,244 KB
testcase_20 AC 762 ms
93,688 KB
testcase_21 AC 769 ms
94,016 KB
testcase_22 AC 738 ms
92,608 KB
testcase_23 AC 773 ms
94,664 KB
testcase_24 AC 741 ms
95,632 KB
testcase_25 AC 764 ms
93,636 KB
testcase_26 AC 773 ms
94,636 KB
testcase_27 AC 735 ms
93,052 KB
testcase_28 AC 774 ms
94,672 KB
testcase_29 AC 699 ms
93,304 KB
testcase_30 AC 764 ms
95,340 KB
testcase_31 AC 707 ms
91,712 KB
testcase_32 AC 712 ms
92,860 KB
testcase_33 AC 752 ms
95,312 KB
testcase_34 AC 724 ms
92,672 KB
testcase_35 AC 766 ms
94,224 KB
testcase_36 AC 746 ms
93,336 KB
testcase_37 AC 719 ms
92,484 KB
testcase_38 AC 672 ms
91,696 KB
testcase_39 AC 739 ms
93,848 KB
testcase_40 AC 736 ms
93,648 KB
testcase_41 AC 730 ms
93,612 KB
testcase_42 AC 787 ms
94,756 KB
testcase_43 AC 678 ms
91,612 KB
testcase_44 AC 493 ms
72,260 KB
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 AC 782 ms
95,412 KB
testcase_49 AC 774 ms
95,800 KB
testcase_50 AC 764 ms
95,556 KB
testcase_51 AC 784 ms
95,316 KB
testcase_52 AC 779 ms
128,196 KB
権限があれば一括ダウンロードができます

ソースコード

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))
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)
0