题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2365

  我没看懂题目。。。这样理解:一个有向图,要给一些边染色,使得所用的颜色最多,且S到T的任意路径的都包含所有颜色。  或者: 给定一个无向图,图中有一个起点S和一个终点T。要求选K个集合S1,S2,…,SK,每个集合都含有图中的一些边,任意两个不同的集合的交集为空。并且从图中任意去掉一个集合,S到T都没有通路。要求K尽量大。

  容易想到最短距离就是总共的数量tot,然后在图上求一个层次图,只要点的距离标号i<=tot的时候点标记为i就可以了,如果大于tot,任意1-tot都可以标记。证明比较简单,不多说。。

 //STATUS:C++_AC_10MS_19492KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
//typedef __int64 LL;
//typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Edge{
int u,v,id;
}e[N*N];
int first[N],next[N*N];
int level[N],ans[N][],cnt[N],vise[N*N];
int Case,n,m,S,T,mt,tot; void adde(int a,int b,int c)
{
e[mt].u=a,e[mt].v=b,e[mt].id=c;
next[mt]=first[a],first[a]=mt++;
e[mt].u=b,e[mt].v=a,e[mt].id=c;
next[mt]=first[b],first[b]=mt++;
} int bfs(int flag)
{
int i,j,u,v,d;
queue<int> q;
q.push(S);
level[S]=;
while(!q.empty()){
u=q.front();q.pop();
for(i=first[u];i!=-;i=next[i]){
if(flag){
if(!vise[e[i].id]){
vise[e[i].id]=;
d=level[e[i].u]>tot?:level[u];
ans[d][cnt[d]++]=e[i].id;
}
}
// else if(e[i].v==T)return level[e[i].u];
if(!level[e[i].v]){
level[e[i].v]=level[u]+;
q.push(e[i].v);
}
}
}
return level[T]-;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,a,b;
scanf("%d",&Case);
while(Case--)
{
scanf("%d%d%d%d",&n,&m,&S,&T);
mem(first,-);mt=;
for(i=;i<=m;i++){
scanf("%d%d",&a,&b);
adde(a,b,i);
} mem(level,);
tot=bfs();
mem(level,);mem(cnt,);mem(vise,);
bfs(); printf("%d\n",tot);
for(i=;i<=tot;i++){
printf("%d",cnt[i]);
sort(ans[i],ans[i]+cnt[i]);
for(j=;j<cnt[i];j++){
printf(" %d",ans[i][j]);
}
putchar('\n');
}
}
return ;
}

ZOJ-2365 Strong Defence 贪心,BFS的更多相关文章

  1. ZOJ 1301 The New Villa (BFS + 状态压缩)

    题意:黑先生新买了一栋别墅,可是里面的电灯线路的连接是很混乱的(每个房间的开关可能控制其他房间,房间数<=10),有一天晚上他回家时发现所有的灯(除了他出发的房间)都是关闭的,而他想回卧室去休息 ...

  2. #292 (div.2) D.Drazil and Tiles (贪心+bfs)

    Description Drazil created a following problem about putting  ×  tiles into an n × m grid: "The ...

  3. ZOJ 1649:Rescue(BFS)

    Rescue Time Limit: 2 Seconds      Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...

  4. hdu-1728(贪心&&bfs的灵活运用吧)

    链接 [https://vjudge.net/contest/256476#problem/D] 题意 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到 ...

  5. bzoj 1193 贪心+bfs

    1193: [HNOI2006]马步距离 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2015  Solved: 914[Submit][Statu ...

  6. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

  7. bzoj1193: [HNOI2006]马步距离(贪心+bfs)

    1193: [HNOI2006]马步距离 题目:传送门 题解: 毒瘤题... 模拟赛时的一道题,刚开始以为是一道大难题...一直在拼命找规律 结果.... 还是说正解吧: 暴力的解法肯定是直接bfs, ...

  8. 清北学堂-贪心-bfs

    输入样例: 3 5 10 5 4 10 8 1 10 1 3 1 4 1 5 1 3 2 1 2 5 4 3 4 3 4 5 5 1 1 4 4 6 1 9 4 7 2 9 5 10 5 2 8 8 ...

  9. poj 1689 && zoj 1422 3002 Rubbery (Geometry + BFS)

    ZOJ :: Problems :: Show Problem 1689 -- 3002 Rubbery 这题是从校内oj的几何分类里面找到的. 题意不难,就是给出一个区域(L,W),这个区域里面有很 ...

随机推荐

  1. 【BZOJ】1088: [SCOI2005]扫雷Mine

    1088: [SCOI2005]扫雷Mine Description 相 信大家都玩过扫雷的游戏.那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”人国流行起了一种简单的 ...

  2. Java内存管理:深入Java内存区域

    Java与C++之间有一堵由内存动态分配和垃圾收集技术所围成的高墙,墙外面的人想进去,墙里面的人却想出来. 概述: 对于从事C和C++程序开发的开发人员来说,在内存管理领域,他们既是拥有最高权力的皇帝 ...

  3. 制作精灵(UI Sprite)

    怎样判断是否应该使用精灵 在一套UI中,精灵是一种非常常见的元件.当制作UI时,如果需要显示一张图片,需要先判断这个图片是否应该制作到图集里去,然后用精灵的方式去使用它,一般来说,可以遵循以下规律. ...

  4. hdu 1828 Picture(线段树 || 普通hash标记)

    http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others)    Mem ...

  5. 使用Yeoman搭建 AngularJS 应用 (2) —— 让我们搭建一个网页应用

    原文地址:http://yeoman.io/codelab/index.html 使用Yeoman搭建简单的应用 今天将会搭建一个简单的网页程序.你将可以添加,删除,拖拽和保存. 浏览Yeoman Y ...

  6. C,C++,JAVA char,各占字节数

    char在C和C+中占一个字节 Java中无论是汉字还是英文字母都是用Unicode编码来表示的,一个Unicode码是16位,每字节是8位,所以一个Unicode码占两字节 /** * The nu ...

  7. 原生javascript效果:无缝滚动

    <style type="text/css"> #con {width:400px; padding:10px; margin:20px auto; text-alig ...

  8. CentOS查看CPU信息、位数、多核信息

    # uname -a Linux localhost.localdomain 2.6.18-164.el5PAE #1 SMP Thu Sep 3 04:10:44 EDT 2009 i686 i68 ...

  9. 不改变中间层,如何玩转 .NET 的远程处理功能?

    原文链接: https://msdn.microsoft.com/enus/library/aa289846(v=vs.71).aspx Visual Studio .NET 2003 该方案展示了传 ...

  10. IB_DESIGNABLE的使用

    创建LHQTextField 继承自: UITextField 将我自定义的textField在面板中进行关联 此时,在设置刚来添加的属性的值的时候,就会立马出效果