当前位置:网站首页>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;
}
边栏推荐
- Daily question 1 - force deduction - there are three consecutive arrays of odd numbers
- Draw multiple ROC curves on a graph
- Service grid ASM year end summary: how do end users use the service grid?
- Qt QFrame详解
- 软件工程师与软件开发区别? Software Engineer和Software Developer区别?
- QT program packaging and publishing windeployqt tool
- VerilogA——动态比较器
- GenICam GenTL 标准 ver1.5(3)第四章
- Error: GPG check FAILED Once install MySQL
- NoSQL數據庫之Redis(五):Redis_Jedis_測試
猜你喜欢

json tobean

Li Kou today's question -324 Swing sort II

Redis of NoSQL database (II): introduction to redis configuration file

In vscade, how to use eslint to lint and format

配置Flutter开发环境

Annual inventory review of Alibaba cloud's observable practices in 2021

Unity ar shadow shadow

Uniapp obtains the date implementation of the beginning and end of the previous month and the next month

UVM authentication platform

About DDNS
随机推荐
Redis (4) of NoSQL database: redis new data type
Daily question - force deduction - multiply the found value by 2
centos下配置mysql 5.7 和 8
To: Hou Hong: the key to enterprise digital transformation is not technology, but strategy
Qt QFrame详解
QT foreach keyword
flutter配置国内镜像,连接真机
Solve the problem that NPM does not have permission
QT custom bit operation class
try anbox (by quqi99)
JDBC connects to the database and socket sends the client.
NoSQL数据库之Redis(四):Redis的发布和订阅
Redis in NoSQL database (4): redis publishing and subscription
融入STEAM教育的劳动技能课程
JDBC连接数据库,socket发送客户端。
消息队列之通过幂等设计和原子锁避免重复退款
Class differences of QT processing image data (qpixmap, qimage, qpicture)
IDEA 集成 码云
【OSPF引入直连路由时巧借静态黑洞路由做汇总】
关于端口转发程序的一点思考