习题6-14(uva-12118)

该博客主要探讨了图论中的奇偶割点概念,并通过C++实现了一个求解图中奇偶割点数量及二分图边数的算法。在给定的图中,利用深度优先搜索遍历节点,计算每个节点删除后的连通分量奇偶性,从而确定奇偶割点,并进一步计算二分图的边数。对于图的遍历和连通性分析,该算法提供了一种有效的解决方案。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int MAXV = 1004;
int V, E, T, Vis[MAXV];
vector<int> G[MAXV];

int dfs(int u)
{
	if (Vis[u]) return 0;
	Vis[u] = 1;
	int sz = G[u].size(), r = sz % 2;
	for (int i = 0; i < sz; i++) {
		r += dfs(G[u][i]);
	}
	return r;
}
int main()
{
	int t = 1;
	while (cin >> V >> E >> T && (V | E | T)) {
		int a, b;
		for (int i = 0; i <= V; i++)G[i].clear();

		memset(Vis, 0, V* sizeof(int));

		for (int i = 0; i < E; i++) {
			cin >> a >> b;
			G[a - 1].push_back(b - 1);
			G[b - 1].push_back(a - 1);
		}
		int n = 0, resp = E;
		for (int i = 0; i < V; i++) {
			if(Vis[i] || G[i].empty()) continue;
			n++;
			resp += max(0, (dfs(i) - 2) / 2);
		}
		cout << "Case " << t++ << ": " << T * (resp + max(0, n - 1)) << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值