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

Problem Description
MZL is an active girl who has her own country.

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.

 
Input
The first contains one integer T(T<=50),indicating the number of tests.

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.

 
Output
The First line Ans is the maximal number of the city rebuilt,the second line is a array of length of tot describing the plan you give(tot is the number of the operation of type 1).
 
Sample Input
1
5 6 2
2 1 2
2 1 3
1 1
1 2
3 1 1 2
1 2
 
Sample Output
3
0 2 1
 
Hint

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.

 
Source
 
解题:拆点做最大匹配,倒着匈牙利即可以字典序最小
 
 #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的更多相关文章

  1. Hdu 5352 MZL's City (多重匹配)

    题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一 ...

  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 ...

  3. 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 ...

  4. HDU 5352 MZL's City (2015 Multi-University Training Contest 5)

    题目大意: 一个地方的点和道路在M年前全部被破坏,每年可以有三个操作, 1.把与一个点X一个联通块内的一些点重建,2.连一条边,3.地震震坏一些边,每年最多能重建K个城市,问最多能建多少城市,并输出操 ...

  5. HDU 5352 MZL's City

    最小费用最大流,因为要控制字典序,网络流控制不好了...一直WA,所以用了费用流,时间早的费用大,时间晚的费用少. 构图: 建立一个超级源点和超级汇点.超级源点连向1操作,容量为K,费用为COST,然 ...

  6. HDU 5352——MZL's City——————【二分图多重匹配、拆点||网络流||费用流】

    MZL's City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. 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 ...

  8. 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:  ...

  9. 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 ...

随机推荐

  1. osEye.Net:离别是为了将来的重逢

    这一时刻已经成为osEye历史..... 在热心网友的关怀和鼓励之下,osEye.net将继续运行着,感谢你们陪伴osEye一起走过.... 与你相知相恋已经有4个年头了,你的成长到成熟都让我历历在目 ...

  2. iOS库--.a与.framework

    一.什么是库? 库是共享程序代码的方式,一般分为静态库和动态库. 二.静态库与动态库的差别? 静态库:链接时完整地拷贝至可运行文件里.被多次使用就有多份冗余拷贝. 动态库:链接时不复制.程序执行时由系 ...

  3. robot framework环境配置

    1.Robot framework的安装 作用:web自动化测试框架. RF框架是基于python 的,所以一定要有python环境.网上可以自行查找. 下载地址:https://pypi.pytho ...

  4. python爬虫系列序

    关于爬虫的了解,始于看到这篇分析从数据角度解析福州美食,和上份工作中的短暂参与. 长长短短持续近一年的时间,对其态度越来越明晰,噢原来这就是我想从事的工作. 于是想要系统学习的心理便弥散开来…… 参考 ...

  5. 【Hibernate步步为营】--单向关联一对一映射

    上篇文章对多对一的关联映射做了具体的分析,它在实现上能够有两种方式,而且这两种方式实现也非常easy,关键是标签<many-to-one>的使用,它分别指明了多端和一端的映射关系.这样的映 ...

  6. 英语发音规则---D字母

    英语发音规则---D字母 一.总结 一句话总结: 1.D发[d]音? doctor ['dɒktə] n. 医生:博士 bread [bred] n. 面包:生计 hand [hænd] n. 手,手 ...

  7. JavaScript中数组的迭代方法:forEach、map、filter、reduce、every、some、for in、for of

    JavaScript中有非常多数组迭代方法,这里基本上吧所有的都介绍全了,我项目中比较喜欢的是forEach. 7.for in (for-in循环实际是为循环对象而设计的,for in也可以循环数组 ...

  8. C# MVC登录判断状态

    public class AuthenAdminAttribute:FilterAttribute,IAuthorizationFilter { public void OnAuthenticatio ...

  9. 使用BigDecimal完成小数点后的精确位数的四舍五入

    package com.ryan; import java.math.BigDecimal; class MyMath { public static double round(double num ...

  10. Caffe CommonLayer分析

    Caffe CommonLayer分析 \(Caffe\)中包含了很多通用的功能层,包含了\(concat\),\(slice\),\(split\),\(crop\),\(flip\),\(scal ...