結果
問題 |
No.2202 贅沢てりたまチキン
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:16:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 219 ms / 2,000 ms |
コード長 | 990 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 82,036 KB |
実行使用メモリ | 130,092 KB |
最終ジャッジ日時 | 2025-03-20 21:17:36 |
合計ジャッジ時間 | 4,188 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
import sys sys.setrecursionlimit(1 << 25) def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx +=1 M = int(data[idx]) idx +=1 parent = [i for i in range(2 * N + 1)] # 1-based to 2N def find(u): while parent[u] != u: parent[u] = parent[parent[u]] u = parent[u] return u def union(u, v): u_root = find(u) v_root = find(v) if u_root == v_root: return parent[v_root] = u_root for _ in range(M): A = int(data[idx]) idx +=1 B = int(data[idx]) idx +=1 uA = A dA = A + N uB = B dB = B + N union(uA, dB) union(dA, uB) # Check for all 1..N stations for i in range(1, N+1): if find(i) != find(i + N): print("No") return print("Yes") if __name__ == '__main__': main()