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 ...
随机推荐
- nodejs-基础大杂烩(待整理)
优点:安装简易,能自动配置环境变量 缺点:更新和更换版本需重新安装(这个可以用包管理器解决,不是问题) 高手推荐使用开源的NVM包管理器来更新和安装node,可能这个包在linux平台上比较好用吧 g ...
- 多线程程序调用fork的现象
- 用PHP去实现静态化
我们在PHP站点开发过程中为了站点的推广或者SEO的须要,须要对站点进行一定的静态化,这里设计到什么是静态页面,所谓的静态页面.并非页面中没有动画等元素,而是指网页的代码都在页面中,即不须要再去执行P ...
- 路由器一键桥接Android实现
開始之前,首先说一下什么叫一键桥接,所谓一键桥接,就是点击一下.就能够对所连接的路由器进行网络中继设置.以实现路由器能够通过已有的无线路由器进行网络訪问. 那么实现这个功能有几种方法呢?能够说有非常多 ...
- Linux安装vmtools
unbantu下,先把DVD的Vmwarew.gz,文件拷贝到tmp文件.然后 tar zxf VMware Tools-0....... ls cd ./intall.pl 有个文件,先拷贝到roo ...
- Mediator Design Pattern 中介者模式
就是设计一个Mediator类,能够处理其它类的关系. Mediator类: 1 拥有其它全部类的实例对象 2 设置一个接口供其它类使用,其它类也拥有一个Mediator类成员,仅仅需调用这个Medi ...
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- windows下PTAM的编译
前些日子在研究PTAM,以下首先说说PTAM的编译过程,我在XP几WIN7搭配vs2010中均已測试过,都能够执行. 首先下载编译PTAM所必须的库文件.下载地址我会给出 PTAM(PTAM.zip) ...
- lightoj--1354-- IP Checking(水题)
IP Checking Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu Submit Sta ...
- BZOJ 2819 DFS序+线段树
非递归的DFS写炸了- 交了一个递归版的 过了---.. //By SiriusRen #include <cstdio> #include <cstring> #includ ...