当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

And check the collection hello

Qt 串口编程

Effective methods for construction enterprises to select smart construction sites

About DDNS

Two methods for preorder traversal of binary tree

Redis (4) of NoSQL database: redis new data type

Message queue avoiding repeated refund by idempotent design and atomic lock

NoSQL数据库介绍

Domestic code hosting center code cloud

As a qualified network worker, you must master DHCP snooping knowledge!
随机推荐
Chinese garbled code on idea console [valid through personal test]
Better than postman! Apipost knows more about Chinese programmers! How delicious!
微信小程序学习笔记(暑假)
List collection implements paging
To: Hou Hong: the key to enterprise digital transformation is not technology, but strategy
Qt QFrame详解
And check the collection hello
等保备案主体是谁?在当地网安进行备案是吗?
WDCP accesses all paths that do not exist and jumps to the home page without returning 404
期末总结——Spark
NoSQL数据库介绍
QT serial port programming
Database - Synonyms
[translation] [Chapter 2 ②] mindshare PCI Express technology 3.0
多模态 —— Learnable pooling with Context Gating for video classification
Genicam gentl standard ver1.5 (3) Chapter 4
JDBC连接数据库,socket发送客户端。
大型化工企业数字化转型建议
QT qframe details
In vscade, how to use eslint to lint and format