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 ...
随机推荐
- HDU 2439 The Mussels
The Mussels Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID ...
- C# try-catch-return
正常执行try后才能执行finally,catch中的语句可能会影响finally的执行 使用 finally 块,可以清理在 Try 中分配的任何资源,而且,即使在 try 块中发生异常,您也可以运 ...
- Qt Installer Framework的学习(三)
Qt Installer Framework的学习(三) Qt Installer Framework的样例中.通常是这种:config目录一般放了一个config.xml文件,包括的是安装配置xml ...
- Cocos2d-x3.0 RenderTexture(三)
.h #include "cocos2d.h" #include "cocos-ext.h" #include "ui/CocosGUI.h" ...
- hdu2767 Proving Equivalences,有向图强联通,Kosaraju算法
点击打开链接 有向图强联通,Kosaraju算法 缩点后分别入度和出度为0的点的个数 answer = max(a, b); scc_cnt = 1; answer = 0 #include<c ...
- c++面向对象程序设计 谭浩强 第二章答案
类体内定义成员函数 #include <iostream> using namespace std; class Time { public: void set_time(); void ...
- ubuntu中不能远程连接解决
今天装好ubuntu19.04之后不能远程连接,网上找了很久终于自己解决了.ap 步骤如下:希望对各位有用,哪里不对请指出 第一步我们需要加载openssh-server 等待加载完毕后, ...
- mongo服务器异常
1.Detected unclean shutdown - /data/db/mongod.lock is not empty. 前几天把研究用的虚拟机直接关了回家过年,今天启动发现启动不了,报了个u ...
- Android: HowTo设置app不被系统kill掉
有一种方法可以设置app永远不会被kill,AndroidManifest.xml 中添加: android:persistent="true" 适用于放在/system/app下 ...
- Memcache相关面试题
1)memcached的cache机制是怎样的? 懒惰算法 +最近最少使用原则 2)memcached如何实现冗余机制? 冗余:就是有好多好多不经常使用的. 可以不用实现冗余机制,如果非要实现.那就搞 ...