Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo314 committed Nov 10, 2023
1 parent 8ccc0ab commit e6d61f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/graph_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::vector<std::vector<int>> connected_components(const Graph<Cost>& graph) {
std::vector<std::vector<int>> groups;
std::vector<bool> visited(graph.n);
for (int i = 0; i < graph.n; i++) {
if (color[i] != -1) continue;
if (visited[i]) continue;
std::stack<int> stk;
stk.push(i);
visited[i] = true;
Expand Down
26 changes: 26 additions & 0 deletions test/atcoder-abc282-d.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#define PROBLEM "https://atcoder.jp/contests/abc282/tasks/abc282_d"

Check failure on line 1 in test/atcoder-abc282-d.test.cpp

View workflow job for this annotation

GitHub Actions / verify

failed to verify

#include <array>

#include "../cpp/graph_util.hpp"

int main(void) {
int N, M;
std::cin >> N >> M;
Graph<int> graph(N);
graph.read(M);
std::vector<int> c = bipartite_coloring(graph);
if (c.empty()) {
std::cout << 0 << std::endl;
return 0;
}
std::vector<std::vector<int>> groups = connected_components(graph);
long long ans = (long long)N * (N - 1) / 2 - M;
for (const std::vector<int>& group : groups) {
std::array<long long, 2> wb = {};
std::for_each(group.begin(), group.end(), [&](int x) { wb[c[x]]++; });
auto [w, b] = wb;
ans -= w * (w - 1) / 2 + b * (b - 1) / 2;
}
std::cout << ans << std::endl;
}

0 comments on commit e6d61f4

Please sign in to comment.