当前位置:网站首页>uva10859
uva10859
2022-06-29 06:38:00 【小刀刺大熊】
#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 maxn = 1007,MOD = 2000;
vector<int> edge[maxn];
int vis[maxn][2], d[maxn][2], n, m;
int dp(int cur, int flag, int fa) {
if (vis[cur][flag]) return d[cur][flag];
vis[cur][flag] = 1;
int &ans = d[cur][flag];
ans = MOD;
for (int i = 0; i < edge[cur].size(); i++) {
int nx = edge[cur][i];
if (nx == fa)continue;
ans += dp(nx,1,cur);
}
if (!flag && fa != -1) ++ans;
if (flag || fa == -1) {
int sum = 0;
for (int i = 0; i < edge[cur].size(); i++) {
int nx = edge[cur][i];
if (nx == fa) continue;
sum += dp(nx, 0, cur);
}
if (fa != -1) sum++;
ans = min(ans, sum);
}
return ans;
}
int main()
{
int t,a,b;
cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 0; i < n; i++) edge[i].clear();
for (int i = 0; i < m; i++) {
cin >> a >> b;
edge[a].push_back(b);
edge[b].push_back(a);
}
memset(vis, 0, sizeof(vis));
int ans = 0;
for (int i = 0; i < n; i++) {
if (!vis[i][0]) {
ans += dp(i, 0, -1);
}
}
cout << ans / MOD << " " << m - ans % MOD << " " << ans % MOD << endl;
}
return 0;
}
边栏推荐
- [C language] flexible array
- Output of character pointer to string in C language
- QT program packaging and publishing windeployqt tool
- Configuring the flutter development environment
- mongostat性能分析
- UVM验证平台
- 存token获取token刷新token发送header头
- jetson tx2
- Qt QLineEdit详解
- Crawler data analysis (introduction 2-re analysis)
猜你喜欢
随机推荐
Print Yanghui triangle
Vite quick start
RPC和RMI
Mongostat performance analysis
Introduction to NoSQL database
NoSQL数据库之Redis(四):Redis的发布和订阅
centos下配置mysql 5.7 和 8
二叉树的迭代法前序遍历的两种方法
更改主机名的方法(永久)
VerilogA - dynamic comparator
Json tobean
QT program packaging and publishing windeployqt tool
Analysis on the wave of learning robot education for children
What are the conditions for a high-quality public chain?
jetson tx2
融入STEAM教育的劳动技能课程
Class differences of QT processing image data (qpixmap, qimage, qpicture)
Ci tool Jenkins II: build a simple CI project
[translation] [Chapter II ①] mindshare PCI Express technology 3.0
Some thoughts on port forwarding program








