随笔分类 -  图论性质

HDU 4001 To Miss Our Children Time
摘要:一开始我一直想的是简单图论问题,构图SPFA求最长路,发现这样做有环不好处理。比如这组样例:21 1 1 01 1 1 0构图就会有环,不能直接SPFA,tarjan缩点的话应该可以做,但是代码量就太大了。可以这样去处理:bool cmp(block a,block b) { if(a.x!=b.x)return a.x<b.x; if(a.y!=b.y)return a.y<b.y; return a.d>b.d; } void build(){ //缩点,避免产生环 sort(x,x+n,cmp); int cnt=1; y[1]=x[0]; for(int i=1;i& 阅读全文

posted @ 2012-03-24 21:38 c语言源码 阅读(199) 评论(0) 推荐(0)

BOJ 292 MABODX
摘要:MABODXAccept:17 Submit:88Time Limit:4000MS Memory Limit:65536KBDescriptionThere is a country which has N city. Because The king spend littlemoney on the road ,so there is one and only one path from any cityto another city,every city has a apple tree.The apple in one citywhich has only one apple tree 阅读全文

posted @ 2012-02-23 21:56 c语言源码 阅读(150) 评论(0) 推荐(0)

POJ 3683 Priest John's Busiest Day
摘要:2-SAT经典问题#include<cstdio> #include<string.h> #include<math.h> #include<stack> #define N 2010 #define M N*N*3 using namespace std; struct edge{ int v,next; }edge[M]; int n; int s[N],t[N],seq[N]; int cnt,head1[N],head2[N],head3[N]; int scc,index,dfn[N],low[N],belong[N]; int top 阅读全文

posted @ 2012-02-17 22:06 c语言源码 阅读(193) 评论(0) 推荐(0)

POJ 3160 Father Christmas flymouse
摘要:很简单的一道题,先tarjan缩点,然后SPFA求最长路。#include<cstdio> #include<string.h> #include<math.h> #include<queue> #define N 30100 #define M 150100 using namespace std; struct edge{ int v,next; }edge[M]; int n,m; int num[N]; int cnt,head1[N],head2[N]; int scc,index,dfn[N],low[N],belong[N],sum 阅读全文

posted @ 2012-02-16 22:08 c语言源码 阅读(136) 评论(0) 推荐(0)

POJ 3728 The merchant
摘要:这个题算是LCA的一个高级应用吧。其实就是在维护u,v到其最近公共祖先的几个数据(将u,v分成两段,一个从u到LCA(u,v),一个从LCA(u,v)到v,分别维护即可)#include<cstdio> #include<string.h> #include<math.h> #define con 50100 using namespace std; int head1[con],head2[con],head3[con],p,n,num[con],mi[con],mx[con],up[con],down[con],vis[con],f[50100],ans 阅读全文

posted @ 2012-02-16 13:16 c语言源码 阅读(204) 评论(0) 推荐(0)

LCA问题 poj1330 / poj1470
摘要:Tarjan算法(离线算法)模板#include<cstdio> #include<string.h> using namespace std; int n,head[10010],k,x,y,d[10010],f[10010],ans[10010],num[10010]; bool visit[10010]; struct point{ int to; int next; }edge[10010]; void addedge(int a,int b){ edge[k].to=b; edge[k].next=head[a]; head[a]=k++; } int fin 阅读全文

posted @ 2012-02-12 20:00 c语言源码 阅读(203) 评论(0) 推荐(0)

导航