当前位置:网站首页>uva10859
uva10859
2022-06-29 07:15:00 【Stabbing the bear with a knife】
#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;
}
边栏推荐
猜你喜欢

How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli

QT serial port programming

JDBC connects to the database and socket sends the client.

通过keyup监听textarea输入更改按钮样式

利用IPv6實現公網訪問遠程桌面

About DDNS
![[answer all questions] CSDN question and answer function evaluation](/img/32/571c9c5f4eb7f69173ae79b8dcf427.jpg)
[answer all questions] CSDN question and answer function evaluation

How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli

YGG pilipinas: typhoon Odette disaster relief work update

转:侯宏:企业数字化转型的关键不是技术,而是战略
随机推荐
About DDNS
期末总结——Spark
Summary of some new datasets proposed by cvpr2021
Common status codes for page error reporting
2022.6.27-----leetcode. five hundred and twenty-two
Two methods for preorder traversal of binary tree
JDBC connects to the database and socket sends the client.
利用Jsonp跨域请求数据
Unexpected exception ... code: Badrequest when downloading Xilinx 2018.2
How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli
Method of changing host name (permanent)
Utilisation d'IPv6 pour réaliser l'accès public au bureau distant
Daily question 1 - force deduction - there are three consecutive arrays of odd numbers
Differences between JSON objects and JSON strings
IDEA常用插件
Chinese garbled code on idea console [valid through personal test]
消息队列之通过幂等设计和原子锁避免重复退款
[translation] [Chapter 2 ③] mindshare PCI Express technology 3.0
IDEA 集成 码云
Twitter launches the test of anti abuse tool "safe mode" and adds enabling prompt