// シンプルな嘘乱択 #include #include #include #include #include #include using namespace std; #include int main() { cin.tie(nullptr), ios::sync_with_stdio(false); auto START = std::chrono::system_clock::now(); int N, M; cin >> N >> M; vector> edges; for (int i = 0; i < M; i++) { int u, v, w; cin >> u >> v >> w; u--, v--, w--; edges.emplace_back(u, v, w); } int ret = 0; vector state(M); std::mt19937 rng(159376); std::vector idx(M); iota(idx.begin(), idx.end(), 0); while (true) { int64_t spent_ms = std::chrono::duration_cast(std::chrono::system_clock::now() - START).count(); if (spent_ms > 500) break; std::shuffle(idx.begin(), idx.end(), rng); atcoder::dsu uf(N); int tmp = 0; for (auto e : idx) { auto [u, v, w] = edges[e]; assert(u != v and v != w and u != w); if (!uf.same(u, v) and !uf.same(v, w) and !uf.same(u, w)) { uf.merge(u, v), uf.merge(v, w); tmp++; } } if (ret < tmp) ret = tmp; } cout << ret << '\n'; }