結果
問題 | No.8107 Listening |
ユーザー | MasKoaTS |
提出日時 | 2024-04-01 22:03:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,048 ms / 2,000 ms |
コード長 | 634 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 82,436 KB |
実行使用メモリ | 264,064 KB |
最終ジャッジ日時 | 2024-09-30 22:27:52 |
合計ジャッジ時間 | 34,794 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
def maximal_matching(G): M = set() # Initialize an empty set for the matching sorted_edges = sorted(G.edges, key=lambda e: e.weight) # Sort edges by weight for edge in sorted_edges: u, v = edge.vertices if u not in M and v not in M: M.add(edge) return M n, m = map(int, input().split()) edges = [[x - 1 for x in map(int, input().split())] + [i] for i in range(1, m + 1)] edges.sort(key = lambda e : e[2]) st = set([]) ans = [] for u, v, w in edges: if(u not in st and v not in st): ans.append(w) st.add(u) st.add(v) print(len(ans)) for x in ans: print(x)