#include using namespace std; const int MAXN = 100005; vector adj[MAXN]; int N, M; bool visited[MAXN]; // DFS function to find connected components void dfs(int node, set& component) { visited[node] = true; component.insert(node); for (int neighbor : adj[node]) { if (!visited[neighbor]) { dfs(neighbor, component); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); // Reading input ifstream fin("connection.in"); ofstream fout("connection.out"); fin >> N >> M; for (int i = 0; i < M; i++) { int a, b; fin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } // Finding the initial connected components memset(visited, false, sizeof(visited)); vector> components; for (int i = 1; i <= N; i++) { if (!visited[i]) { set component; dfs(i, component); components.push_back(component); } } // Counting valid vertex pairs long long valid_pairs = 0; for (auto& component : components) { long long size = component.size(); valid_pairs += (size * (size - 1)) / 2; } fout << valid_pairs << "\n"; return 0; }