题目链接: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. javascript editor

    http://www.jetbrains.com/webstorm/download/download_thanks.jsp?os=win

  2. EL四大作用域 9个jsp对象有效范围 及 对应的类

    java中request,session,application的作用范围 page,request,session,application四者的作用范围: page的作用范围是当前页面:对应El表达 ...

  3. 1行代码为每个Controller自定义“TabBar”-b

    这篇文章大致会带你实现以下的功能,废话少说,先看东西: JPNavigationController.gif Q&A:Demo里都有那些东西? 01.关于自定义导航栏 01.第一个控制器的导航 ...

  4. js展开更多

    var introduces = { inIt : function(){ introduces.imgLoad(); introduces.showMore(0,'hioh',86); introd ...

  5. 深入WSGI,并按样例实现一个

    感觉WSGI确实和SERVLET相似,为PYTHON提供了运行和管理环境.WSGI服务器和PYTHON的WEB框架一起,实现WEB响应. 步骤: 首先,服务器启动并加载一个由Web框架/应用提供的可调 ...

  6. 2013年最受欢迎的16个HTML5 WordPress主题

    本文中,我整理了16个最新.最受欢迎的WordPress主题,它们一致的特征是支持HTML5, 它们秉承最佳设计理念以及最新的流行趋势,将它们归纳与此,希望对喜欢HTML5,准备用WordPress做 ...

  7. app与server联系

    --- /frameworks/base/services/java/com/android/server目录下SystemServer.java 在ServerThread的run函数中增加加载Rf ...

  8. XBMC 最新版本错误

    1. Syntax error: "(" unexpected 修改 tools/depends下的makefile.include 将NDK_VER=0x9d

  9. Bex64

    http://speedupcomputercleaner.com/windows-7-error-bex64.php   How To Fix Windows 7 Error Bex64 ? Wha ...

  10. 如何配置Java环境

    下载JDK并安装 搜索JDK,官网立马就出来了,下载之后个人觉得毕竟开发,毕竟这东西不大,C盘稳一点,安装在C盘可以的 配置 右键打开计算机->属性->高级系统设置->高级-> ...