2015 Multi-University Training Contest 5 hdu 5352 MZL's City
MZL's City
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 743 Accepted Submission(s): 260
Her big country has N cities numbered from 1 to N.She has controled the country for so long and she only remebered that there was a big earthquake M years ago,which made all the roads between the cities destroyed and all the city became broken.She also remebered that exactly one of the following things happened every recent M years:
1.She rebuild some cities that are connected with X directly and indirectly.Notice that if a city was rebuilt that it will never be broken again.
2.There is a bidirectional road between city X and city Y built.
3.There is a earthquake happened and some roads were destroyed.
She forgot the exactly cities that were rebuilt,but she only knew that no more than K cities were rebuilt in one year.Now she only want to know the maximal number of cities that could be rebuilt.At the same time she want you to tell her the smallest lexicographically plan under the best answer.Notice that 8 2 1 is smaller than 10 0 1.
For each test,the first line contains three integers N,M,K(N<=200,M<=500,K<=200),indicating the number of MZL’s country ,the years happened a big earthquake and the limit of the rebuild.Next M lines,each line contains a operation,and the format is “1 x” , “2 x y”,or a operation of type 3.
If it’s type 3,first it is a interger p,indicating the number of the destoyed roads,next 2*p numbers,describing the p destoyed roads as (x,y).It’s guaranteed in any time there is no more than 1 road between every two cities and the road destoyed must exist in that time.
No city was rebuilt in the third year,city 1 and city 3 were rebuilt in the fourth year,and city 2 was rebuilt in the sixth year.
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int N,M,K;
struct arc {
int to,next;
arc(int x = ,int y = -) {
to = x;
next = y;
}
} e[];
int head[],Link[maxn],ans[maxn],tot;
bool used[maxn],mp[maxn][maxn];
void add(int u,int v) {
e[tot] = arc(v,head[u]);
head[u] = tot++;
}
bool match(int u) {
for(int i = head[u]; ~i; i = e[i].next) {
if(!used[e[i].to]) {
used[e[i].to] = true;
if(Link[e[i].to] == - || match(Link[e[i].to])) {
Link[e[i].to] = u;
return true;
}
}
}
return false;
}
vector<int>con;
bool vis[maxn];
void dfs(int u) {
vis[u] = true;
con.push_back(u);
for(int i = ; i <= N; ++i)
if(mp[u][i] && !vis[i])
dfs(i);
}
int hungary(int tot){
int ret = ;
memset(ans,,sizeof ans);
for(int i = tot-; i >= ; --i){
for(int j = ; j < K; ++j){
memset(used,false,sizeof used);
if(match(i*K + j)){
ret++;
ans[i]++;
}
}
}
return ret;
}
int main(int c) {
int kase,op,u,v,tot;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d%d",&N,&M,&K);
memset(head,-,sizeof head);
memset(mp,false,sizeof mp);
memset(Link,-,sizeof Link);
for(int i = tot = ::tot = ; i < M; ++i) {
scanf("%d",&op);
switch(op) {
case :
memset(vis,false,sizeof vis);
scanf("%d",&u);
con.clear();
dfs(u);
for(int j = ; j < K; ++j) {
for(int k = con.size()-; k >= ; --k)
add(tot*K + j,con[k]);
}
++tot;
break;
case :
scanf("%d%d",&u,&v);
mp[u][v] = mp[v][u] = true;
break;
case :
scanf("%d",&op);
while(op--) {
scanf("%d%d",&u,&v);
mp[u][v] = mp[v][u] = false;
}
break;
default:
break;
}
}
printf("%d\n",hungary(tot));
for(int i = ; i < tot; ++i)
printf("%d%c",ans[i],i+==tot?'\n':' ');
}
return ;
}
2015 Multi-University Training Contest 5 hdu 5352 MZL's City的更多相关文章
- Hdu 5352 MZL's City (多重匹配)
题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一 ...
- 2015 Multi-University Training Contest 5 hdu 5348 MZL's endless loop
MZL's endless loop Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- 2015 Multi-University Training Contest 5 hdu 5349 MZL's simple problem
MZL's simple problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5352 MZL's City (2015 Multi-University Training Contest 5)
题目大意: 一个地方的点和道路在M年前全部被破坏,每年可以有三个操作, 1.把与一个点X一个联通块内的一些点重建,2.连一条边,3.地震震坏一些边,每年最多能重建K个城市,问最多能建多少城市,并输出操 ...
- HDU 5352 MZL's City
最小费用最大流,因为要控制字典序,网络流控制不好了...一直WA,所以用了费用流,时间早的费用大,时间晚的费用少. 构图: 建立一个超级源点和超级汇点.超级源点连向1操作,容量为K,费用为COST,然 ...
- HDU 5352——MZL's City——————【二分图多重匹配、拆点||网络流||费用流】
MZL's City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
随机推荐
- MySQL多线程数据导入导出工具Mydumper
http://afei2.sinaapp.com/?p=456 今天在线上使用mysqldump将数据表从一个库导入到另外一个库,结果速度特别慢,印象中有个多线程的数据导入导出工具Mydumper,于 ...
- POJ 2111
记忆化搜索即可,设DP[I][J]为可到达的最大步数. 输出时用了一种较笨拙的方法,还有一种方法是使用最长上升子序列的方式,挺好,先排序,这让我想起上次BESTCODER的一题 #include &l ...
- WebService CXF学习:复杂对象传递(List,Map)
转自:https://blog.csdn.net/z69183787/article/details/35988335 第一步:创建存储复杂对象的类(因为WebServices的复杂对象的传递,一定要 ...
- Spring mvc 实现jsonp和json数据类型
在使用springmvc开发rest接口的时候很方便,可以直接使用@ResponseBody注解,直接加在springmvc的控制器类的方法上,springmvc会直接为我们将返回的对 ...
- Tomcat 初探(二) server.xml 配置
前言 在上一篇文章中,我们在示例中演示了网站的发布,其中涉及到了 server.xml 的修改,本文中我会给大家详细解释一下 server.xml 文件中的节点及其属性的作用,本片文章参考并摘抄了他人 ...
- dozer初探
简介 Dozer是一款javaBean的映射工具,用于解决一个类到另外一个类的自动适配功能,它即支持简单的映射,也支持复杂类型的双向递归映射(官网). 示例 举个例子,假设说我们现在有User(用户) ...
- SQlException 对象名无效
- sql调优《二》
1.数据库设计(是否复合范式,是否合理归档.分区.分表等) 2.硬件基础架构 (设备规格,硬件性能,负载均衡,容灾等) 3.ql语句的写法.索引和统计信息,事务和锁,应用程序访问代码(连接过多.频繁开 ...
- 手游服务器端接入facebook的SDK
手游如果支持facebook登录,就要接入facebook的登录SDK.刚好工作中自己做了这一块的接入功能现在记录分享下来提供一个参考. 当前只是接入了登录这个功能,先简单的说说接入facebook登 ...
- PHP学习过程中遇到的疑难杂症
变量当双引号中包含变量时,变量会与双引号中的内容连接在一起:当单引号中包含变量时,变量会被当做字符串输出. Heredoc结构形式首先使用定界符表示字符串(<<<),接着在“< ...